@geek-fun/serverlessinsight 0.8.6 → 0.8.8

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 (76) hide show
  1. package/.serverlessinsight/state-cdn-flow-app-cdn-flow-service.json.backup +1 -1
  2. package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +2 -2
  3. package/.serverlessinsight/state-insight-poc-app-insight-poc-tencent.json.backup +94 -0
  4. package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +47 -27
  5. package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +1 -1
  6. package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +35 -73
  7. package/.serverlessinsight/state-role-reconcile-test-app-role-reconcile-test-service.json.backup +148 -0
  8. package/AGENTS.md +29 -0
  9. package/dist/package.json +1 -1
  10. package/dist/src/commands/deploy.js +1 -0
  11. package/dist/src/commands/index.js +6 -2
  12. package/dist/src/commands/plan.js +1 -0
  13. package/dist/src/common/aliyunClient/ecsOperations.js +70 -1
  14. package/dist/src/common/aliyunClient/nasOperations.js +21 -0
  15. package/dist/src/common/aliyunClient/ramOperations.js +116 -15
  16. package/dist/src/common/aliyunClient/slsOperations.js +16 -3
  17. package/dist/src/common/concurrency.js +30 -0
  18. package/dist/src/common/context.js +3 -0
  19. package/dist/src/common/dependencyGraph/graph.js +5 -0
  20. package/dist/src/common/iacHelper.js +3 -1
  21. package/dist/src/common/iamStatements.js +21 -1
  22. package/dist/src/common/index.js +5 -0
  23. package/dist/src/common/nameBuilder.js +12 -1
  24. package/dist/src/common/planCompare.js +62 -0
  25. package/dist/src/common/planFormatter.js +15 -3
  26. package/dist/src/common/refreshCache.js +32 -0
  27. package/dist/src/common/refreshPlanner.js +105 -0
  28. package/dist/src/common/tencentClient/camOperations.js +24 -12
  29. package/dist/src/common/tencentClient/clsOperations.js +27 -3
  30. package/dist/src/common/tencentClient/tdsqlcOperations.js +22 -0
  31. package/dist/src/common/throttleRetry.js +56 -0
  32. package/dist/src/common/volcengineClient/iamOperations.js +15 -11
  33. package/dist/src/common/volcengineClient/tlsOperations.js +12 -4
  34. package/dist/src/lang/en.js +23 -0
  35. package/dist/src/lang/zh-CN.js +22 -0
  36. package/dist/src/stack/aliyunStack/apigwExecutor.js +5 -5
  37. package/dist/src/stack/aliyunStack/apigwPlanner.js +75 -7
  38. package/dist/src/stack/aliyunStack/apigwResource.js +10 -8
  39. package/dist/src/stack/aliyunStack/apigwTypes.js +86 -5
  40. package/dist/src/stack/aliyunStack/databasePlanner.js +26 -62
  41. package/dist/src/stack/aliyunStack/deployer.js +33 -3
  42. package/dist/src/stack/aliyunStack/esServerlessTypes.js +50 -1
  43. package/dist/src/stack/aliyunStack/fc3Executor.js +5 -3
  44. package/dist/src/stack/aliyunStack/fc3Planner.js +299 -12
  45. package/dist/src/stack/aliyunStack/fc3Resource.js +358 -34
  46. package/dist/src/stack/aliyunStack/fc3Types.js +61 -1
  47. package/dist/src/stack/aliyunStack/ossPlanner.js +21 -63
  48. package/dist/src/stack/aliyunStack/ossTypes.js +25 -1
  49. package/dist/src/stack/aliyunStack/rdsTypes.js +38 -1
  50. package/dist/src/stack/aliyunStack/sharedLogProject.js +22 -5
  51. package/dist/src/stack/aliyunStack/tablestorePlanner.js +20 -74
  52. package/dist/src/stack/aliyunStack/tablestoreTypes.js +33 -1
  53. package/dist/src/stack/scfStack/cosPlanner.js +30 -50
  54. package/dist/src/stack/scfStack/cosTypes.js +29 -1
  55. package/dist/src/stack/scfStack/esServerlessPlanner.js +21 -54
  56. package/dist/src/stack/scfStack/esServerlessTypes.js +13 -1
  57. package/dist/src/stack/scfStack/scfExecutor.js +5 -3
  58. package/dist/src/stack/scfStack/scfPlanner.js +72 -51
  59. package/dist/src/stack/scfStack/scfResource.js +109 -12
  60. package/dist/src/stack/scfStack/scfTypes.js +35 -1
  61. package/dist/src/stack/scfStack/sharedLogset.js +12 -3
  62. package/dist/src/stack/scfStack/tdsqlcPlanner.js +37 -55
  63. package/dist/src/stack/scfStack/tdsqlcTypes.js +21 -1
  64. package/dist/src/stack/volcengineStack/apigwPlanner.js +59 -8
  65. package/dist/src/stack/volcengineStack/apigwResource.js +52 -30
  66. package/dist/src/stack/volcengineStack/apigwTypes.js +44 -8
  67. package/dist/src/stack/volcengineStack/sharedLogProject.js +9 -3
  68. package/dist/src/stack/volcengineStack/tosPlanner.js +28 -55
  69. package/dist/src/stack/volcengineStack/tosTypes.js +18 -1
  70. package/dist/src/stack/volcengineStack/vefaasExecutor.js +5 -3
  71. package/dist/src/stack/volcengineStack/vefaasPlanner.js +119 -10
  72. package/dist/src/stack/volcengineStack/vefaasResource.js +112 -13
  73. package/dist/src/stack/volcengineStack/vefaasTypes.js +61 -7
  74. package/dist/src/validator/semanticValidation.js +41 -0
  75. package/dist/tsconfig.tsbuildinfo +1 -1
  76. package/package.json +1 -1
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cachedRefreshRead = exports.createRefreshCache = void 0;
4
+ const logger_1 = require("./logger");
5
+ const lang_1 = require("../lang");
6
+ const throttleRetry_1 = require("./throttleRetry");
7
+ const createRefreshCache = () => {
8
+ const inflight = new Map();
9
+ return {
10
+ read: (key, load) => {
11
+ const existing = inflight.get(key);
12
+ if (existing) {
13
+ logger_1.logger.debug(lang_1.lang.__('REFRESH_CACHE_HIT', { key }));
14
+ return existing;
15
+ }
16
+ const promise = (0, throttleRetry_1.withThrottleRetry)(load).catch((error) => {
17
+ inflight.delete(key);
18
+ throw error;
19
+ });
20
+ inflight.set(key, promise);
21
+ return promise;
22
+ },
23
+ };
24
+ };
25
+ exports.createRefreshCache = createRefreshCache;
26
+ /**
27
+ * Read-through helper for planner call sites: uses the context-scoped cache
28
+ * when present, otherwise loads directly. Planners receive the context as a
29
+ * parameter, so tests can decide whether caching applies.
30
+ */
31
+ const cachedRefreshRead = (context, key, load) => (context.refreshCache ? context.refreshCache.read(key, load) : load());
32
+ exports.cachedRefreshRead = cachedRefreshRead;
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.planRefreshedResource = exports.decideRefreshedExistsAction = void 0;
4
+ const hashUtils_1 = require("./hashUtils");
5
+ const planCompare_1 = require("./planCompare");
6
+ const decideRefreshedExistsAction = async (args) => {
7
+ const remote = await args.read();
8
+ if (!remote) {
9
+ return { action: 'create', drifted: true };
10
+ }
11
+ let attributes = args.cloudToDefinition(remote);
12
+ if (args.enrichRemoteAttributes) {
13
+ attributes = await args.enrichRemoteAttributes(remote, attributes);
14
+ }
15
+ const remoteDiffers = (0, planCompare_1.remoteDiffersFromDesired)(attributes, args.desiredDefinition);
16
+ if (args.definitionChanged || remoteDiffers) {
17
+ return { action: 'update', drifted: true };
18
+ }
19
+ const extra = await args.extraUpdate?.();
20
+ if (extra?.update) {
21
+ return { action: 'update', drifted: extra.drifted };
22
+ }
23
+ return { action: 'noop' };
24
+ };
25
+ exports.decideRefreshedExistsAction = decideRefreshedExistsAction;
26
+ /**
27
+ * Shared planner skeleton (issue #234 Phase 3): covers the uniform
28
+ * no-state-probe / exists-refresh decision chain of the simple planners
29
+ * (buckets, tables, databases). Function and gateway planners keep their
30
+ * custom flows (role probes, trigger reconciliation, config normalization).
31
+ * Read failures on the exists path degrade to a create plan — the pre-existing
32
+ * planner behavior, preserved verbatim.
33
+ */
34
+ const planRefreshedResource = async (args) => {
35
+ const { logicalId, resourceType, currentState, desiredDefinition } = args;
36
+ if (!currentState || currentState.status === 'tainted') {
37
+ const probeRead = args.probeRead ?? args.read;
38
+ const remote = await probeRead();
39
+ if (remote && !args.isOwned(remote)) {
40
+ throw args.foreignError(remote);
41
+ }
42
+ return {
43
+ logicalId,
44
+ action: 'create',
45
+ resourceType,
46
+ changes: { after: desiredDefinition },
47
+ };
48
+ }
49
+ const normalize = args.normalizeForDisplay ?? ((d) => d);
50
+ const currentDefinition = currentState.definition || {};
51
+ const normalizedCurrent = normalize(currentDefinition);
52
+ const normalizedDesired = normalize(desiredDefinition);
53
+ const definitionChanged = !(0, hashUtils_1.attributesEqual)(normalizedCurrent, normalizedDesired);
54
+ const refreshEnabled = args.refresh ?? true;
55
+ try {
56
+ // --no-refresh: no cloud knowledge, so no drift claims — intent-diff only.
57
+ if (!refreshEnabled) {
58
+ if (!definitionChanged) {
59
+ return { logicalId, action: 'noop', resourceType };
60
+ }
61
+ return {
62
+ logicalId,
63
+ action: 'update',
64
+ resourceType,
65
+ changes: { before: normalizedCurrent, after: normalizedDesired },
66
+ };
67
+ }
68
+ const decision = await (0, exports.decideRefreshedExistsAction)({
69
+ read: args.read,
70
+ cloudToDefinition: args.cloudToDefinition,
71
+ enrichRemoteAttributes: args.enrichRemoteAttributes,
72
+ desiredDefinition,
73
+ definitionChanged,
74
+ extraUpdate: args.extraUpdate,
75
+ });
76
+ if (decision.action === 'noop') {
77
+ return { logicalId, action: 'noop', resourceType };
78
+ }
79
+ if (decision.action === 'create') {
80
+ return {
81
+ logicalId,
82
+ action: 'create',
83
+ resourceType,
84
+ changes: { before: normalize(currentDefinition), after: desiredDefinition },
85
+ drifted: true,
86
+ };
87
+ }
88
+ return {
89
+ logicalId,
90
+ action: 'update',
91
+ resourceType,
92
+ changes: { before: normalizedCurrent, after: normalizedDesired },
93
+ ...(decision.drifted ? { drifted: true } : {}),
94
+ };
95
+ }
96
+ catch {
97
+ return {
98
+ logicalId,
99
+ action: 'create',
100
+ resourceType,
101
+ changes: { before: normalize(currentDefinition), after: desiredDefinition },
102
+ };
103
+ }
104
+ };
105
+ exports.planRefreshedResource = planRefreshedResource;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createCamOperations = void 0;
4
4
  const iamStatements_1 = require("../iamStatements");
5
+ const nameBuilder_1 = require("../nameBuilder");
5
6
  const logger_1 = require("../logger");
6
7
  const lang_1 = require("../../lang");
7
8
  // SCF built-in execution policy (same idea as Aliyun's FC_EXECUTION_POLICY)
@@ -37,8 +38,9 @@ const mapToCamStatement = (stmt) => {
37
38
  }
38
39
  return result;
39
40
  };
40
- const buildExecutionPolicy = (customStatements) => {
41
- const merged = (0, iamStatements_1.mergePolicyStatements)(SCF_EXECUTION_STATEMENTS, customStatements, mapToCamStatement);
41
+ const buildExecutionPolicy = (customStatements, executionStatements) => {
42
+ const baseline = executionStatements?.map(mapToCamStatement) ?? SCF_EXECUTION_STATEMENTS;
43
+ const merged = (0, iamStatements_1.mergePolicyStatements)(baseline, customStatements, mapToCamStatement);
42
44
  return (0, iamStatements_1.buildPolicyDocument)(merged, { version: '2.0' });
43
45
  };
44
46
  const buildAssumeRolePolicy = (trustedServices) => JSON.stringify({
@@ -104,7 +106,17 @@ const createCamOperations = (camClient) => {
104
106
  }
105
107
  };
106
108
  return {
107
- createRole: async (roleName, trustedServices, description, customStatements, managedPolicies) => {
109
+ getOwnerUin: async () => {
110
+ try {
111
+ const response = await camClient.GetUserAppId(undefined);
112
+ return response.OwnerUin ?? response.Uin ?? undefined;
113
+ }
114
+ catch (error) {
115
+ logger_1.logger.warn(lang_1.lang.__('TENCENT_UIN_FETCH_FAILED', { error: String(error) }));
116
+ return undefined;
117
+ }
118
+ },
119
+ createRole: async (roleName, trustedServices, description, customStatements, managedPolicies, executionStatements) => {
108
120
  const assumeRolePolicy = buildAssumeRolePolicy(trustedServices);
109
121
  try {
110
122
  const response = await camClient.CreateRole({
@@ -129,11 +141,11 @@ const createCamOperations = (camClient) => {
129
141
  roleArn,
130
142
  };
131
143
  // Attach inline policy with built-in + custom statements
132
- const policyName = `${roleName}-policy`;
144
+ const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
133
145
  try {
134
146
  await camClient.CreatePolicy({
135
147
  PolicyName: policyName,
136
- PolicyDocument: buildExecutionPolicy(customStatements),
148
+ PolicyDocument: buildExecutionPolicy(customStatements, executionStatements),
137
149
  Description: `SCF execution policy for ${roleName}`,
138
150
  });
139
151
  await attachPolicy(roleName, policyName);
@@ -170,12 +182,12 @@ const createCamOperations = (camClient) => {
170
182
  try {
171
183
  const getResponse = await camClient.GetRole({ RoleName: roleName });
172
184
  const roleData = getResponse.RoleInfo;
173
- const policyName = `${roleName}-policy`;
185
+ const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
174
186
  // Re-attach built-in policy (idempotent)
175
187
  try {
176
188
  await camClient.CreatePolicy({
177
189
  PolicyName: policyName,
178
- PolicyDocument: buildExecutionPolicy(customStatements),
190
+ PolicyDocument: buildExecutionPolicy(customStatements, executionStatements),
179
191
  Description: `SCF execution policy for ${roleName}`,
180
192
  });
181
193
  await attachPolicy(roleName, policyName);
@@ -219,7 +231,7 @@ const createCamOperations = (camClient) => {
219
231
  roleId: roleData.RoleId,
220
232
  roleArn: roleData.RoleArn,
221
233
  description: roleData.Description,
222
- policyName: `${roleName}-policy`,
234
+ policyName: (0, nameBuilder_1.buildRolePolicyName)(roleName),
223
235
  };
224
236
  }
225
237
  catch (error) {
@@ -232,7 +244,7 @@ const createCamOperations = (camClient) => {
232
244
  }
233
245
  },
234
246
  deleteRole: async (roleName, managedPolicies) => {
235
- const policyName = `${roleName}-policy`;
247
+ const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
236
248
  // Detach managed policies first (don't delete them)
237
249
  if (managedPolicies && managedPolicies.length > 0) {
238
250
  for (const policyArn of managedPolicies) {
@@ -256,8 +268,8 @@ const createCamOperations = (camClient) => {
256
268
  throw error;
257
269
  }
258
270
  },
259
- updateRolePolicy: async (roleName, customStatements) => {
260
- const policyName = `${roleName}-policy`;
271
+ updateRolePolicy: async (roleName, customStatements, executionStatements) => {
272
+ const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
261
273
  // Detach + delete old
262
274
  await detachPolicy(roleName, policyName);
263
275
  await deletePolicyByName(camClient, policyName);
@@ -265,7 +277,7 @@ const createCamOperations = (camClient) => {
265
277
  try {
266
278
  await camClient.CreatePolicy({
267
279
  PolicyName: policyName,
268
- PolicyDocument: buildExecutionPolicy(customStatements),
280
+ PolicyDocument: buildExecutionPolicy(customStatements, executionStatements),
269
281
  Description: `SCF execution policy for ${roleName}`,
270
282
  });
271
283
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createClsOperations = void 0;
3
+ exports.createClsOperations = exports.CLS_TOPIC_STORAGE_TYPE = exports.CLS_TOPIC_PERIOD = void 0;
4
4
  const polling_1 = require("../polling");
5
5
  const constants_1 = require("../constants");
6
6
  // CLS reports missing resources with `ResourceNotFound.<Kind>NotExist` codes —
@@ -23,6 +23,11 @@ const isAlreadyExists = (error) => {
23
23
  code.includes('ResourceExists') ||
24
24
  message.includes('already exist'));
25
25
  };
26
+ // The topic attributes si creates with (issue #234 M3): `fn.log` is a
27
+ // boolean — these are stack constants, so live values differing from them are
28
+ // out-of-band drift.
29
+ exports.CLS_TOPIC_PERIOD = 30;
30
+ exports.CLS_TOPIC_STORAGE_TYPE = 'hot';
26
31
  const createClsOperations = (clsClient) => {
27
32
  const operations = {
28
33
  createLogset: async (logsetName, tags) => {
@@ -47,6 +52,12 @@ const createClsOperations = (clsClient) => {
47
52
  Tags: found.Tags,
48
53
  };
49
54
  },
55
+ getLogsetNameById: async (logsetId) => {
56
+ const response = await clsClient.DescribeLogsets({
57
+ Filters: [{ Key: 'logsetId', Values: [logsetId] }],
58
+ });
59
+ return response?.Logsets?.find((l) => l.LogsetId === logsetId)?.LogsetName ?? null;
60
+ },
50
61
  listTopicsByLogset: async (logsetId) => {
51
62
  const response = await clsClient.DescribeTopics({
52
63
  Filters: [{ Key: 'logsetId', Values: [logsetId] }],
@@ -64,6 +75,19 @@ const createClsOperations = (clsClient) => {
64
75
  });
65
76
  return response?.Topics?.find((t) => t.TopicName === topicName) ?? null;
66
77
  },
78
+ getTopicById: async (topicId) => {
79
+ const response = await clsClient.DescribeTopics({
80
+ Filters: [{ Key: 'topicId', Values: [topicId] }],
81
+ });
82
+ return response?.Topics?.find((t) => t.TopicId === topicId) ?? null;
83
+ },
84
+ modifyTopic: async (topicId, opts) => {
85
+ await clsClient.ModifyTopic({
86
+ TopicId: topicId,
87
+ Period: opts.period,
88
+ StorageType: opts.storageType,
89
+ });
90
+ },
67
91
  waitForTopic: async (logsetId, topicName) => (0, polling_1.pollUntil)({
68
92
  description: `CLS topic ${topicName} to become visible`,
69
93
  fetch: () => operations.getTopicByName(logsetId, topicName),
@@ -77,8 +101,8 @@ const createClsOperations = (clsClient) => {
77
101
  await clsClient.CreateTopic({
78
102
  LogsetId: logsetId,
79
103
  TopicName: topicName,
80
- StorageType: opts.storageType ?? 'hot',
81
- Period: opts.period ?? 30,
104
+ StorageType: opts.storageType ?? exports.CLS_TOPIC_STORAGE_TYPE,
105
+ Period: opts.period ?? exports.CLS_TOPIC_PERIOD,
82
106
  Tags: opts.tags.map((t) => ({ Key: t.key, Value: t.value })),
83
107
  });
84
108
  const topic = await operations.waitForTopic(logsetId, topicName);
@@ -165,6 +165,28 @@ const createTdsqlcOperations = (cynosdbClient, context) => {
165
165
  throw error;
166
166
  }
167
167
  },
168
+ getServerlessStrategy: async (clusterId) => {
169
+ // DescribeServerlessStrategy reports the CONFIGURED idle-pause switch
170
+ // (DescribeClusters only reports the running state). The dedicated API
171
+ // is recent — guard on SDK support and treat absence as "not readable".
172
+ const sdk = cynosdbClient;
173
+ if (typeof sdk.DescribeServerlessStrategy !== 'function') {
174
+ return null;
175
+ }
176
+ try {
177
+ const response = await sdk.DescribeServerlessStrategy({ ClusterId: clusterId });
178
+ if (!response) {
179
+ return null;
180
+ }
181
+ return {
182
+ autoPause: response.AutoPause === undefined ? undefined : response.AutoPause === 'yes',
183
+ autoPauseDelay: response.AutoPauseDelay,
184
+ };
185
+ }
186
+ catch {
187
+ return null;
188
+ }
189
+ },
168
190
  updateCluster: async (clusterId, config) => {
169
191
  const params = {
170
192
  ClusterId: clusterId,
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withThrottleRetry = exports.isThrottlingError = void 0;
4
+ const retryUtils_1 = require("./retryUtils");
5
+ /**
6
+ * Provider management-API throttling recognition (issue #234). Error shapes
7
+ * differ across SDKs: Alibaba/Volcengine/Tencent expose `code`, Volcengine TLS
8
+ * nests it under `response.data.Error.Code`, and Tencent scopes the frequency
9
+ * limit as `RequestLimitExceeded.UinLimitExceeded` etc. All three families map
10
+ * onto one recognizer because none of the SDKs retry throttling by default.
11
+ */
12
+ const isThrottlingCode = (code) => {
13
+ if (typeof code === 'string') {
14
+ return (code.startsWith('Throttling') ||
15
+ code.startsWith('RequestLimitExceeded') ||
16
+ code === 'FlowLimitExceeded' ||
17
+ code === 'SlowDown' ||
18
+ code === 'TooManyRequests');
19
+ }
20
+ return code === 100018; // Volcengine FlowLimitExceeded numeric code
21
+ };
22
+ const isThrottlingError = (error) => {
23
+ if (!error || typeof error !== 'object') {
24
+ return false;
25
+ }
26
+ const candidate = error;
27
+ if (isThrottlingCode(candidate.code)) {
28
+ return true;
29
+ }
30
+ return isThrottlingCode(candidate.response?.data?.Error?.Code);
31
+ };
32
+ exports.isThrottlingError = isThrottlingError;
33
+ const RETRY_DELAY_BASE_MS = 250;
34
+ const RETRY_JITTER_MAX_MS = 150;
35
+ const jitteredBackoff = (attempt) => RETRY_DELAY_BASE_MS * 2 ** attempt + Math.floor(Math.random() * RETRY_JITTER_MAX_MS);
36
+ /**
37
+ * Retries a load only on recognized throttling errors with exponential backoff
38
+ * + jitter. Used on the refresh/plan read path; write operations must not be
39
+ * auto-retried through this helper (idempotency is their caller's concern).
40
+ */
41
+ const withThrottleRetry = async (load, maxAttempts = 3) => {
42
+ let attempt = 0;
43
+ for (;;) {
44
+ try {
45
+ return await load();
46
+ }
47
+ catch (error) {
48
+ attempt += 1;
49
+ if (!(0, exports.isThrottlingError)(error) || attempt >= maxAttempts) {
50
+ throw error;
51
+ }
52
+ await (0, retryUtils_1.sleep)(jitteredBackoff(attempt - 1));
53
+ }
54
+ }
55
+ };
56
+ exports.withThrottleRetry = withThrottleRetry;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createIamOperations = void 0;
4
4
  const iamStatements_1 = require("../iamStatements");
5
+ const nameBuilder_1 = require("../nameBuilder");
5
6
  const logger_1 = require("../logger");
6
7
  const lang_1 = require("../../lang");
7
8
  const DEFAULT_TRUST_POLICY_SERVICES = ['vefaas'];
@@ -54,8 +55,11 @@ const mapToVolcengineStatement = (stmt) => {
54
55
  }
55
56
  return result;
56
57
  };
57
- const buildExecutionPolicy = (customStatements) => {
58
- const merged = (0, iamStatements_1.mergePolicyStatements)(VEFAAS_EXECUTION_STATEMENTS, customStatements, mapToVolcengineStatement);
58
+ const buildExecutionPolicy = (baseline, customStatements) => {
59
+ const nativeBaseline = baseline
60
+ ? baseline.map(mapToVolcengineStatement)
61
+ : VEFAAS_EXECUTION_STATEMENTS;
62
+ const merged = (0, iamStatements_1.mergePolicyStatements)(nativeBaseline, customStatements, mapToVolcengineStatement);
59
63
  return (0, iamStatements_1.buildPolicyDocument)(merged);
60
64
  };
61
65
  // TagResources expects flat numbered query params (ResourceIds.1, Tags.1.Key, ...).
@@ -69,8 +73,8 @@ const buildTagResourceQuery = (roleName, tags) => {
69
73
  }, { ResourceType: 'role', 'ResourceIds.1': roleName });
70
74
  };
71
75
  const createIamOperations = (iamClient) => {
72
- const createAndAttachPolicy = async (roleName, customStatements) => {
73
- const policyName = `${roleName}-policy`;
76
+ const createAndAttachPolicy = async (roleName, baseline, customStatements) => {
77
+ const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
74
78
  try {
75
79
  await iamClient.fetchOpenAPI({
76
80
  Action: 'CreatePolicy',
@@ -79,7 +83,7 @@ const createIamOperations = (iamClient) => {
79
83
  headers: { 'content-type': 'application/json' },
80
84
  query: {
81
85
  PolicyName: policyName,
82
- PolicyDocument: buildExecutionPolicy(customStatements),
86
+ PolicyDocument: buildExecutionPolicy(baseline, customStatements),
83
87
  Description: `veFaaS execution policy for ${roleName}`,
84
88
  },
85
89
  });
@@ -136,7 +140,7 @@ const createIamOperations = (iamClient) => {
136
140
  return policyName;
137
141
  };
138
142
  const detachAndDeletePolicy = async (roleName) => {
139
- const policyName = `${roleName}-policy`;
143
+ const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
140
144
  try {
141
145
  await iamClient.fetchOpenAPI({
142
146
  Action: 'DetachRolePolicy',
@@ -261,7 +265,7 @@ const createIamOperations = (iamClient) => {
261
265
  });
262
266
  const data = (response.Result || {});
263
267
  const roleData = (data.Role || {});
264
- const policyName = await createAndAttachPolicy(roleName, customStatements);
268
+ const policyName = await createAndAttachPolicy(roleName, config.executionStatements, customStatements);
265
269
  if (config.managedPolicies && config.managedPolicies.length > 0) {
266
270
  for (const policyArn of config.managedPolicies) {
267
271
  await attachRolePolicyImpl(roleName, policyArn, 'System');
@@ -302,7 +306,7 @@ const createIamOperations = (iamClient) => {
302
306
  TrustPolicyDocument: trustPolicyDocument,
303
307
  },
304
308
  });
305
- const policyName = await createAndAttachPolicy(roleName);
309
+ const policyName = await createAndAttachPolicy(roleName, config.executionStatements, config.customStatements);
306
310
  if (config.managedPolicies && config.managedPolicies.length > 0) {
307
311
  for (const policyArn of config.managedPolicies) {
308
312
  await attachRolePolicyImpl(roleName, policyArn, 'System');
@@ -355,7 +359,7 @@ const createIamOperations = (iamClient) => {
355
359
  createdTime: roleData.CreateTime,
356
360
  maxSessionDuration: roleData.MaxSessionDuration,
357
361
  trustPolicyDocument: roleData.TrustPolicyDocument,
358
- policyName: `${roleName}-policy`,
362
+ policyName: (0, nameBuilder_1.buildRolePolicyName)(roleName),
359
363
  };
360
364
  }
361
365
  catch (error) {
@@ -425,9 +429,9 @@ const createIamOperations = (iamClient) => {
425
429
  detachRolePolicy: async (roleName, policyName) => {
426
430
  await detachRolePolicyImpl(roleName, policyName);
427
431
  },
428
- updateRolePolicy: async (roleName, customStatements) => {
432
+ updateRolePolicy: async (roleName, baseline, customStatements) => {
429
433
  await detachAndDeletePolicy(roleName);
430
- await createAndAttachPolicy(roleName, customStatements);
434
+ await createAndAttachPolicy(roleName, baseline, customStatements);
431
435
  logger_1.logger.info(lang_1.lang.__('IAM_ROLE_POLICY_UPDATED', { roleName }));
432
436
  },
433
437
  listAttachedRolePolicies: async (roleName) => {
@@ -1,11 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTlsOperations = void 0;
3
+ exports.createTlsOperations = exports.TLS_TOPIC_SHARDS = exports.TLS_TOPIC_TTL = void 0;
4
4
  const logger_1 = require("../logger");
5
5
  const lang_1 = require("../../lang");
6
6
  const polling_1 = require("../polling");
7
7
  const WAIT_INTERVAL_MS = 5000;
8
8
  const MAX_WAIT_ATTEMPTS = 30;
9
+ // The topic attributes si creates with (issue #234 M5): `fn.log` is a
10
+ // boolean — these are stack constants, so live values differing from them are
11
+ // out-of-band drift. ModifyTopic cannot change shard count (create-only).
12
+ exports.TLS_TOPIC_TTL = 30;
13
+ exports.TLS_TOPIC_SHARDS = 1;
9
14
  const waitForProjectReady = async (getProject, projectName) => {
10
15
  try {
11
16
  await (0, polling_1.pollUntil)({
@@ -195,8 +200,8 @@ const createTlsOperations = (tlsClient) => {
195
200
  ProjectId: project.projectId,
196
201
  TopicName: config.topicName,
197
202
  Description: config.description,
198
- Ttl: config.ttl ?? 30,
199
- ShardCount: 1,
203
+ Ttl: config.ttl ?? exports.TLS_TOPIC_TTL,
204
+ ShardCount: exports.TLS_TOPIC_SHARDS,
200
205
  });
201
206
  logger_1.logger.info(lang_1.lang.__('TLS_TOPIC_CREATED', { topicName: config.topicName }));
202
207
  return {
@@ -204,7 +209,7 @@ const createTlsOperations = (tlsClient) => {
204
209
  topicName: config.topicName,
205
210
  projectName: config.projectName,
206
211
  description: config.description,
207
- ttl: config.ttl ?? 30,
212
+ ttl: config.ttl ?? exports.TLS_TOPIC_TTL,
208
213
  status: 'Active',
209
214
  };
210
215
  }
@@ -259,6 +264,9 @@ const createTlsOperations = (tlsClient) => {
259
264
  throw error;
260
265
  }
261
266
  },
267
+ modifyTopic: async (topicId, ttl) => {
268
+ await tlsClient.ModifyTopic({ TopicId: topicId, Ttl: ttl });
269
+ },
262
270
  listTopics: async (projectName) => {
263
271
  try {
264
272
  const project = await operations.getProject(projectName);
@@ -118,6 +118,8 @@ exports.en = {
118
118
  PLAN_SUMMARY: 'Plan: {{createCount}} to add, {{updateCount}} to change, {{deleteCount}} to destroy.',
119
119
  PLAN_UNCHANGED_ATTRS: '({{count}} unchanged attributes hidden)',
120
120
  PLAN_COMPUTED_VALUE: '(known after deploy)',
121
+ PLAN_DRIFTED_MARKER: '(drifted — cloud changed outside of this config, will be reconciled)',
122
+ PLAN_DRIFTED_SUMMARY: 'Drift: {{driftedCount}} resource(s) changed in the cloud outside of this config.',
121
123
  // TDSQL-C database messages
122
124
  TDSQL_CLUSTER_CREATION_INITIATED: 'TDSQL-C cluster creation initiated',
123
125
  TDSQL_CLUSTER_CREATION_FAILED: 'Failed to create TDSQL-C cluster',
@@ -230,6 +232,20 @@ exports.en = {
230
232
  SLS_LOGSTORE_WAITING: 'Waiting for SLS logstore {{project}}/{{logstore}} to be ready...',
231
233
  SHARED_SLS_PROJECT_IN_USE: '{{count}} logstore(s) still reference shared SLS project {{projectName}}; retaining it',
232
234
  SHARED_SLS_PROJECT_ADOPTED: 'Adopting existing shared SLS project {{projectName}} owned by this app',
235
+ REFRESH_CACHE_HIT: 'Refresh read cache hit: {{key}}',
236
+ PLAN_FUNCTION_ROLE_MISSING: 'Function {{functionName}} role {{roleName}} is missing in the provider; it will be recreated and rebound on deploy',
237
+ PLAN_FUNCTION_ROLE_PROBE_FAILED: 'Live role policy check for function {{functionName}} (role {{roleName}}) failed: {{error}}; skipping role drift detection for this plan',
238
+ PLAN_FUNCTION_NESTED_PROBE_FAILED: 'Nested resource probe for function {{functionName}} failed: {{error}}; skipping nested drift detection for this plan',
239
+ NESTED_LOGSTORE_RECREATED: 'Logstore {{logstoreName}} was deleted out-of-band; recreating it',
240
+ NESTED_LOGSTORE_UPDATED: 'Logstore {{logstoreName}} attributes drifted; updating to match si defaults',
241
+ NESTED_TLS_TOPIC_UPDATED: 'TLS topic {{topicId}} ttl drifted; updating to match si defaults',
242
+ NESTED_MOUNT_TARGET_RECREATED: 'NAS mount target for file system {{fileSystemId}} was deleted out-of-band; recreating it',
243
+ NESTED_TOPIC_RECREATED: 'CLS topic {{topicId}} was deleted out-of-band; recreating it under the shared logset',
244
+ NESTED_TOPIC_UPDATED: 'CLS topic {{topicId}} attributes drifted; updating to match si defaults',
245
+ NESTED_SG_RULES_REPAIRED: 'Security group {{securityGroupId}} rule set drifted; authorizing {{added}} and revoking {{removed}} rules',
246
+ NESTED_INDEX_RECREATED: 'Logstore index {{logstoreName}} was deleted out-of-band; recreating it',
247
+ PLAN_EVENT_TRIGGER_PROBE_FAILED: 'Live trigger check for API Gateway {{eventName}} failed: {{error}}; skipping trigger drift detection for this plan',
248
+ RAM_ROLE_MISSING_RECREATE: 'RAM role {{roleName}} is missing in the provider; recreating it with the union of all functions that share it',
233
249
  SLS_PROJECT_FOREIGN_OWNED: 'SLS project {{projectName}} exists but is not owned by this app; refusing to adopt',
234
250
  APIGW_LOG_CONFIG_STILL_REFERENCES_STORE: 'Regional PROVIDER gateway log config still references {{slsLogStore}}; retaining logstore',
235
251
  APIGW_DOMAIN_BINDING_FAILED: 'Failed to bind custom domain: {{error}}',
@@ -413,6 +429,10 @@ exports.en = {
413
429
  SEMANTIC_DUPLICATE_GENERATED_API_NAME: 'Generated API Gateway apiName "{{apiName}}" collides between "{{firstPath}}" and "{{secondPath}}" in this deployment; shorten the event name or differentiate trigger method/path',
414
430
  SEMANTIC_DUPLICATE_ROUTE_NAME: 'Generated API Gateway route name "{{routeName}}" collides between "{{firstPath}}" and "{{secondPath}}" in this deployment; shorten the event name or differentiate trigger method/path',
415
431
  SEMANTIC_UNRESOLVED_FUNCTION_BACKEND: 'Trigger backend "{{reference}}" in event "{{eventKey}}" does not match any function definition in the configuration',
432
+ SEMANTIC_BACKEND_BARE_KEY: 'Trigger backend "{{backend}}" in event "{{eventKey}}" matches function key "{{key}}", but bare backend values must be deployed function names. For template functions use the reference form "${functions.{{key}}}"',
433
+ SEMANTIC_BACKEND_BARE_NAME: 'Trigger backend "{{backend}}" in event "{{eventKey}}" resolves to template function "{{key}}" by name; prefer the reference form "${functions.{{key}}}"',
434
+ EXTERNAL_FUNCTION_NOT_FOUND_VOLCENGINE: 'Backend "{{backendRef}}" is not defined in this template and no deployed veFaaS function with that name exists in the provider. External backends must exist in the same account and region',
435
+ EXTERNAL_FUNCTION_BACKEND: 'Backend "{{backendRef}}" is not defined in this template; treating it as an external deployed function name',
416
436
  // Show command messages
417
437
  LOADING_STATE_FOR: 'Loading state for app: {{app}}, service: {{service}}, stage: {{stage}}...',
418
438
  NO_RESOURCES_FOUND: 'No resources found in state.',
@@ -492,6 +512,8 @@ exports.en = {
492
512
  RAM_ROLE_DRIFT_RECOVERY_FAILED: 'Failed to recover from RAM role state drift for "{{roleName}}": {{error}}. ' +
493
513
  'The role existed in the cloud but recovery operations failed. ' +
494
514
  'To fix: manually verify the role in the cloud console, remove it from state, and redeploy.',
515
+ RAM_POLICY_VERSION_PRUNE_FAILED: 'Failed to prune old policy versions for "{{policyName}}": {{error}}. ' +
516
+ 'The policy may exceed the version limit on the next update.',
495
517
  // Certificate messages
496
518
  CERT_INVALID_CONFIGURATION: 'Certificate "{{name}}" must have either (certificate_body + private_key) or certificate_id, but not both',
497
519
  CERT_FILE_NOT_FOUND: 'Certificate file not found: {{filePath}}',
@@ -648,6 +670,7 @@ exports.en = {
648
670
  TENCENT_CAM_ROLE_DELETED: 'Tencent CAM role {{roleName}} deleted',
649
671
  TENCENT_CAM_ROLE_NOT_FOUND: 'Tencent CAM role {{roleName}} not found in cloud provider',
650
672
  TENCENT_CAM_ROLE_ALREADY_EXISTS: 'Tencent CAM role {{roleName}} already exists',
673
+ TENCENT_UIN_FETCH_FAILED: 'Failed to fetch the Tencent UIN; function invoke permissions fall back to a wildcard resource: {{error}}',
651
674
  TENCENT_CAM_ROLE_DRIFT_RECOVERY_FAILED: 'Tencent CAM role drift recovery failed for {{roleName}}: {{error}}',
652
675
  TENCENT_CAM_POLICY_ALREADY_ATTACHED: 'Policy already attached to CAM role {{roleName}}',
653
676
  TENCENT_CAM_POLICY_ALREADY_EXISTS: 'Tencent CAM policy already exists',
@@ -118,6 +118,8 @@ exports.zhCN = {
118
118
  PLAN_SUMMARY: '计划: 新增 {{createCount}} 个,变更 {{updateCount}} 个,销毁 {{deleteCount}} 个。',
119
119
  PLAN_UNCHANGED_ATTRS: '({{count}} 个未变更属性已隐藏)',
120
120
  PLAN_COMPUTED_VALUE: '(部署后可知)',
121
+ PLAN_DRIFTED_MARKER: '(云端已漂移——与本配置不一致,将按配置纠正)',
122
+ PLAN_DRIFTED_SUMMARY: '漂移: {{driftedCount}} 个资源在云端被本配置之外的变更修改。',
121
123
  // TDSQL-C 数据库消息
122
124
  TDSQL_CLUSTER_CREATION_INITIATED: 'TDSQL-C 集群创建已启动',
123
125
  TDSQL_CLUSTER_CREATION_FAILED: '创建 TDSQL-C 集群失败',
@@ -230,6 +232,20 @@ exports.zhCN = {
230
232
  SLS_LOGSTORE_WAITING: '等待 SLS 日志库 {{project}}/{{logstore}} 就绪...',
231
233
  SHARED_SLS_PROJECT_IN_USE: '仍有 {{count}} 个日志库引用共享 SLS 项目 {{projectName}},予以保留',
232
234
  SHARED_SLS_PROJECT_ADOPTED: '采用当前应用已有的共享 SLS 项目 {{projectName}}',
235
+ REFRESH_CACHE_HIT: '刷新读缓存命中:{{key}}',
236
+ PLAN_FUNCTION_ROLE_MISSING: '函数 {{functionName}} 的角色 {{roleName}} 在云端不存在;部署时将重建并重新绑定',
237
+ PLAN_FUNCTION_ROLE_PROBE_FAILED: '函数 {{functionName}}(角色 {{roleName}})的实时角色策略检查失败:{{error}};本次计划跳过角色漂移检测',
238
+ PLAN_FUNCTION_NESTED_PROBE_FAILED: '函数 {{functionName}} 的嵌套资源探测失败:{{error}};本次计划跳过嵌套漂移检测',
239
+ NESTED_LOGSTORE_RECREATED: '日志库 {{logstoreName}} 被带外删除,正在重建',
240
+ NESTED_LOGSTORE_UPDATED: '日志库 {{logstoreName}} 属性已漂移,正在按 si 默认值更新',
241
+ NESTED_TLS_TOPIC_UPDATED: 'TLS 日志主题 {{topicId}} 的 ttl 已漂移,正在按 si 默认值更新',
242
+ NESTED_MOUNT_TARGET_RECREATED: '文件系统 {{fileSystemId}} 的 NAS 挂载点被带外删除,正在重建',
243
+ NESTED_TOPIC_RECREATED: '日志主题 {{topicId}} 被带外删除,正在共享日志集下重建',
244
+ NESTED_TOPIC_UPDATED: '日志主题 {{topicId}} 属性已漂移,正在按 si 默认值更新',
245
+ NESTED_SG_RULES_REPAIRED: '安全组 {{securityGroupId}} 规则集已漂移;新增 {{added}} 条、撤销 {{removed}} 条',
246
+ NESTED_INDEX_RECREATED: '日志库 {{logstoreName}} 的索引被带外删除,正在重建',
247
+ PLAN_EVENT_TRIGGER_PROBE_FAILED: 'API 网关 {{eventName}} 的实时触发器检查失败:{{error}};本次计划跳过触发器漂移检测',
248
+ RAM_ROLE_MISSING_RECREATE: 'RAM 角色 {{roleName}} 在云端不存在;将以共享该角色的所有函数的并集权限重建',
233
249
  SLS_PROJECT_FOREIGN_OWNED: 'SLS 项目 {{projectName}} 已存在但不属于当前应用,拒绝采用',
234
250
  APIGW_LOG_CONFIG_STILL_REFERENCES_STORE: '区域级 PROVIDER 网关日志配置仍引用 {{slsLogStore}},保留该日志库',
235
251
  APIGW_DOMAIN_BINDING_FAILED: '绑定自定义域名失败:{{error}}',
@@ -410,6 +426,10 @@ exports.zhCN = {
410
426
  SEMANTIC_DUPLICATE_GENERATED_API_NAME: '生成的 API Gateway apiName "{{apiName}}" 在 "{{firstPath}}" 与 "{{secondPath}}" 之间发生冲突;请缩短事件名称或区分触发器的 method/path',
411
427
  SEMANTIC_DUPLICATE_ROUTE_NAME: '生成的 API Gateway route name "{{routeName}}" 在 "{{firstPath}}" 与 "{{secondPath}}" 之间发生冲突;请缩短事件名称或区分触发器的 method/path',
412
428
  SEMANTIC_UNRESOLVED_FUNCTION_BACKEND: '事件 "{{eventKey}}" 的触发器后端 "{{reference}}" 未匹配到配置中的任何函数定义',
429
+ SEMANTIC_BACKEND_BARE_KEY: '事件 "{{eventKey}}" 的触发器后端 "{{backend}}" 匹配的是函数 key "{{key}}",但裸值必须是已部署函数名。模板函数请使用引用形式 "${functions.{{key}}}"',
430
+ SEMANTIC_BACKEND_BARE_NAME: '事件 "{{eventKey}}" 的触发器后端 "{{backend}}" 按名称解析为模板函数 "{{key}}",建议使用引用形式 "${functions.{{key}}}"',
431
+ EXTERNAL_FUNCTION_NOT_FOUND_VOLCENGINE: '后端 "{{backendRef}}" 未在本模板中定义,且提供商中不存在同名已部署 veFaaS 函数。外部后端必须位于同一账号和区域',
432
+ EXTERNAL_FUNCTION_BACKEND: '后端 "{{backendRef}}" 未在当前模板中定义,将按外部已部署函数名处理',
413
433
  // Show command messages
414
434
  LOADING_STATE_FOR: '正在加载应用 {{app}}、服务 {{service}}、阶段 {{stage}} 的状态...',
415
435
  NO_RESOURCES_FOUND: '状态中未找到资源。',
@@ -488,6 +508,7 @@ exports.zhCN = {
488
508
  RAM_ROLE_DRIFT_RECOVERY_FAILED: 'RAM 角色 "{{roleName}}" 状态漂移恢复失败:{{error}}。' +
489
509
  '角色在云端存在但恢复操作失败。' +
490
510
  '修复方法:在云控制台手动确认角色状态,从状态中移除该角色并重新部署。',
511
+ RAM_POLICY_VERSION_PRUNE_FAILED: '策略 "{{policyName}}" 旧版本清理失败:{{error}}。' + '下次更新时策略版本数可能超出上限。',
491
512
  // 证书消息
492
513
  CERT_INVALID_CONFIGURATION: '证书 "{{name}}" 必须具有 (certificate_body + private_key) 或 certificate_id,但不能同时存在',
493
514
  CERT_FILE_NOT_FOUND: '未找到证书文件: {{filePath}}',
@@ -642,6 +663,7 @@ exports.zhCN = {
642
663
  TENCENT_CAM_ROLE_DELETED: '腾讯云 CAM 角色 {{roleName}} 删除成功',
643
664
  TENCENT_CAM_ROLE_NOT_FOUND: '腾讯云 CAM 角色 {{roleName}} 在云服务商中未找到',
644
665
  TENCENT_CAM_ROLE_ALREADY_EXISTS: '腾讯云 CAM 角色 {{roleName}} 已存在',
666
+ TENCENT_UIN_FETCH_FAILED: '获取腾讯云 UIN 失败,函数调用权限将回退为资源通配: {{error}}',
645
667
  TENCENT_CAM_ROLE_DRIFT_RECOVERY_FAILED: '腾讯云 CAM 角色 {{roleName}} 状态漂移恢复失败:{{error}}',
646
668
  TENCENT_CAM_POLICY_ALREADY_ATTACHED: 'CAM 角色 {{roleName}} 已附加该策略',
647
669
  TENCENT_CAM_POLICY_ALREADY_EXISTS: '腾讯云 CAM 策略已存在',