@geek-fun/serverlessinsight 0.9.1 → 0.9.3

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 (124) 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 +4 -8
  4. package/.serverlessinsight/state-insight-poc-app-log-insight-poc-tencent-log.json.backup +3 -8
  5. package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +4 -4
  6. package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +1 -1
  7. package/.serverlessinsight/state-insight-poc-timer-app-insight-poc-timer.json.backup +132 -0
  8. package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +2 -2
  9. package/.serverlessinsight/state-insight-volc-nested-app-insight-volc-nested.json.backup +3 -3
  10. package/.serverlessinsight/state-nested-drift-app-nested-drift-service.json.backup +20 -5
  11. package/.serverlessinsight/state-role-reconcile-test-app-role-reconcile-test-service.json.backup +3 -3
  12. package/AGENTS.md +10 -0
  13. package/CHANGELOG.md +51 -0
  14. package/README.md +103 -13
  15. package/README.zh-CN.md +73 -13
  16. package/codecov +0 -0
  17. package/codecov.SHA256SUM +1 -0
  18. package/codecov.SHA256SUM.sig +16 -0
  19. package/dist/package.json +1 -1
  20. package/dist/src/commands/index.js +92 -24
  21. package/dist/src/commands/local.js +16 -3
  22. package/dist/src/commands/plan.js +31 -4
  23. package/dist/src/commands/schema.js +24 -0
  24. package/dist/src/commands/show.js +64 -10
  25. package/dist/src/commands/validate.js +34 -2
  26. package/dist/src/common/aliyunClient/apigwOperations.js +17 -1
  27. package/dist/src/common/aliyunClient/fc3Operations.js +39 -2
  28. package/dist/src/common/aliyunClient/ossOperations.js +214 -221
  29. package/dist/src/common/bucketPolicy.js +63 -0
  30. package/dist/src/common/constants.js +7 -1
  31. package/dist/src/common/domainUtils.js +4 -1
  32. package/dist/src/common/functionDefinition.js +25 -0
  33. package/dist/src/common/index.js +4 -0
  34. package/dist/src/common/jsonOutput.js +82 -0
  35. package/dist/src/common/logger.js +6 -3
  36. package/dist/src/common/nameBuilder.js +3 -1
  37. package/dist/src/common/noColor.js +9 -0
  38. package/dist/src/common/planCapabilities.js +119 -0
  39. package/dist/src/common/planCompare.js +119 -66
  40. package/dist/src/common/planFormatter.js +34 -20
  41. package/dist/src/common/planRedaction.js +26 -0
  42. package/dist/src/common/refreshPlanner.js +66 -21
  43. package/dist/src/common/siCron.js +415 -0
  44. package/dist/src/common/stateBackend/saasStateBackend.js +5 -4
  45. package/dist/src/common/tencentClient/cosOperations.js +326 -322
  46. package/dist/src/common/tencentClient/scfOperations.js +11 -2
  47. package/dist/src/common/tencentClient/tdsqlcOperations.js +6 -11
  48. package/dist/src/common/triggerMapper.js +16 -1
  49. package/dist/src/common/volcengineClient/apigwOperations.js +82 -0
  50. package/dist/src/common/volcengineClient/iamOperations.js +27 -3
  51. package/dist/src/common/volcengineClient/tosOperations.js +62 -56
  52. package/dist/src/common/volcengineClient/vefaasOperations.js +45 -0
  53. package/dist/src/lang/en.js +70 -3
  54. package/dist/src/lang/index.js +36 -1
  55. package/dist/src/lang/zh-CN.js +70 -3
  56. package/dist/src/parser/eventParser.js +1 -0
  57. package/dist/src/parser/functionParser.js +48 -2
  58. package/dist/src/stack/aliyunStack/apigwExecutor.js +1 -1
  59. package/dist/src/stack/aliyunStack/apigwPlanner.js +103 -23
  60. package/dist/src/stack/aliyunStack/apigwResource.js +4 -3
  61. package/dist/src/stack/aliyunStack/apigwTypes.js +3 -7
  62. package/dist/src/stack/aliyunStack/deployer.js +2 -0
  63. package/dist/src/stack/aliyunStack/esServerlessTypes.js +8 -4
  64. package/dist/src/stack/aliyunStack/fc3Executor.js +7 -3
  65. package/dist/src/stack/aliyunStack/fc3Planner.js +148 -153
  66. package/dist/src/stack/aliyunStack/fc3Resource.js +206 -53
  67. package/dist/src/stack/aliyunStack/fc3Types.js +30 -16
  68. package/dist/src/stack/aliyunStack/ossPlanner.js +15 -1
  69. package/dist/src/stack/aliyunStack/ossResource.js +113 -102
  70. package/dist/src/stack/aliyunStack/ossTypes.js +20 -20
  71. package/dist/src/stack/localStack/aliyunFc.js +1 -6
  72. package/dist/src/stack/localStack/event.js +31 -71
  73. package/dist/src/stack/localStack/function.js +25 -77
  74. package/dist/src/stack/localStack/functionRunner.js +10 -2
  75. package/dist/src/stack/localStack/httpAdapter.js +54 -0
  76. package/dist/src/stack/localStack/httpError.js +5 -0
  77. package/dist/src/stack/localStack/index.js +8 -1
  78. package/dist/src/stack/localStack/legacyLambda.js +26 -0
  79. package/dist/src/stack/localStack/localContext.js +29 -0
  80. package/dist/src/stack/localStack/localRoute.js +12 -0
  81. package/dist/src/stack/localStack/localRuntimes.js +22 -0
  82. package/dist/src/stack/localStack/localServer.js +8 -3
  83. package/dist/src/stack/localStack/requestBody.js +24 -0
  84. package/dist/src/stack/localStack/requestId.js +18 -0
  85. package/dist/src/stack/localStack/tencent.js +147 -0
  86. package/dist/src/stack/localStack/timer.js +183 -0
  87. package/dist/src/stack/localStack/utils.js +19 -1
  88. package/dist/src/stack/localStack/volcengine.js +68 -0
  89. package/dist/src/stack/scfStack/cosPlanner.js +9 -14
  90. package/dist/src/stack/scfStack/cosResource.js +42 -50
  91. package/dist/src/stack/scfStack/cosTypes.js +19 -14
  92. package/dist/src/stack/scfStack/deployer.js +2 -0
  93. package/dist/src/stack/scfStack/scfExecutor.js +7 -3
  94. package/dist/src/stack/scfStack/scfHttpTrigger.js +106 -0
  95. package/dist/src/stack/scfStack/scfPlanner.js +114 -29
  96. package/dist/src/stack/scfStack/scfResource.js +329 -311
  97. package/dist/src/stack/scfStack/scfTypes.js +4 -3
  98. package/dist/src/stack/scfStack/tdsqlcPlanner.js +10 -13
  99. package/dist/src/stack/volcengineStack/apigwDomains.js +64 -0
  100. package/dist/src/stack/volcengineStack/apigwPlanner.js +71 -15
  101. package/dist/src/stack/volcengineStack/apigwResource.js +60 -24
  102. package/dist/src/stack/volcengineStack/apigwTypes.js +5 -1
  103. package/dist/src/stack/volcengineStack/deployer.js +6 -0
  104. package/dist/src/stack/volcengineStack/tosPlanner.js +8 -13
  105. package/dist/src/stack/volcengineStack/tosResource.js +22 -35
  106. package/dist/src/stack/volcengineStack/tosTypes.js +5 -8
  107. package/dist/src/stack/volcengineStack/vefaasPlanner.js +186 -44
  108. package/dist/src/stack/volcengineStack/vefaasResource.js +232 -14
  109. package/dist/src/stack/volcengineStack/vefaasTypes.js +6 -3
  110. package/dist/src/validator/functionSchema.js +25 -2
  111. package/dist/src/validator/iacSchema.js +2 -1
  112. package/dist/src/validator/index.js +4 -1
  113. package/dist/src/validator/rootSchema.js +49 -18
  114. package/dist/src/validator/schemaExport.js +60 -0
  115. package/dist/src/validator/semanticValidation.js +79 -0
  116. package/dist/src/validator/templateRefSchema.js +9 -1
  117. package/dist/tsconfig.tsbuildinfo +1 -1
  118. package/package.json +1 -1
  119. package/release-notes.md +79 -0
  120. package/samples/aliyun-poc-timer.yml +39 -0
  121. package/samples/tencent-local/index.js +13 -0
  122. package/samples/tencent-local/serverlessinsight.yml +23 -0
  123. package/samples/volcengine-local/index.js +13 -0
  124. package/samples/volcengine-local/serverlessinsight.yml +28 -0
@@ -205,14 +205,17 @@ const createScfOperations = (scfClient, deps) => {
205
205
  await scfClient.UpdateFunctionCode(params);
206
206
  },
207
207
  createTrigger: async (params) => {
208
- await scfClient.CreateTrigger({
208
+ const response = await scfClient.CreateTrigger({
209
209
  FunctionName: params.FunctionName,
210
210
  TriggerName: params.TriggerName,
211
211
  Type: params.Type,
212
212
  ...(params.TriggerDesc ? { TriggerDesc: params.TriggerDesc } : {}),
213
213
  ...(params.Qualifier ? { Qualifier: params.Qualifier } : {}),
214
214
  ...(params.Enable ? { Enable: params.Enable } : {}),
215
+ ...(params.CustomArgument !== undefined ? { CustomArgument: params.CustomArgument } : {}),
216
+ ...(params.Description ? { Description: params.Description } : {}),
215
217
  });
218
+ return response?.TriggerInfo;
216
219
  },
217
220
  deleteTrigger: async (params) => {
218
221
  await scfClient.DeleteTrigger({
@@ -260,7 +263,13 @@ const createScfOperations = (scfClient, deps) => {
260
263
  }
261
264
  },
262
265
  deleteCustomDomain: async (domain) => {
263
- await scfClient.DeleteCustomDomain({ Domain: domain });
266
+ try {
267
+ await scfClient.DeleteCustomDomain({ Domain: domain });
268
+ }
269
+ catch (error) {
270
+ if (error?.code !== 'ResourceNotFound')
271
+ throw error;
272
+ }
264
273
  },
265
274
  deleteFunction: async (functionName) => {
266
275
  const params = {
@@ -173,19 +173,14 @@ const createTdsqlcOperations = (cynosdbClient, context) => {
173
173
  if (typeof sdk.DescribeServerlessStrategy !== 'function') {
174
174
  return null;
175
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 {
176
+ const response = await sdk.DescribeServerlessStrategy({ ClusterId: clusterId });
177
+ if (!response) {
187
178
  return null;
188
179
  }
180
+ return {
181
+ autoPause: response.AutoPause === undefined ? undefined : response.AutoPause === 'yes',
182
+ autoPauseDelay: response.AutoPauseDelay,
183
+ };
189
184
  },
190
185
  updateCluster: async (clusterId, config) => {
191
186
  const params = {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mapAliyunAccess = exports.mapAccess = exports.mapAuthType = void 0;
3
+ exports.buildTencentHttpTriggerDesc = exports.buildAliyunHttpTriggerConfig = exports.mapAliyunAccess = exports.mapAccess = exports.mapAuthType = void 0;
4
4
  const providerEnum_1 = require("./providerEnum");
5
5
  const mapAuthType = (provider, authType) => {
6
6
  switch (provider) {
@@ -34,3 +34,18 @@ const mapAliyunAccess = (access) => {
34
34
  };
35
35
  };
36
36
  exports.mapAliyunAccess = mapAliyunAccess;
37
+ /** Exact FC3 HTTP trigger write shape, also used for live comparison. */
38
+ const buildAliyunHttpTriggerConfig = (trigger) => ({
39
+ authType: (0, exports.mapAuthType)(providerEnum_1.ProviderEnum.ALIYUN, trigger.auth_type),
40
+ methods: ['GET', 'POST', 'PUT', 'DELETE', 'HEAD', 'PATCH'],
41
+ ...(0, exports.mapAliyunAccess)(trigger.access),
42
+ });
43
+ exports.buildAliyunHttpTriggerConfig = buildAliyunHttpTriggerConfig;
44
+ const buildTencentHttpTriggerDesc = (authType, netConfig) => JSON.stringify({
45
+ AuthType: authType,
46
+ NetConfig: {
47
+ EnableIntranet: netConfig.enableIntranet ?? false,
48
+ EnableExtranet: netConfig.enableExtranet ?? true,
49
+ },
50
+ });
51
+ exports.buildTencentHttpTriggerDesc = buildTencentHttpTriggerDesc;
@@ -25,14 +25,18 @@ const APIGW_POLL_MAX_ATTEMPTS = 120; // up to 20 minutes
25
25
  findServiceByName: async (_g, _n) => notInitialized(),
26
26
  deleteService: async (_id) => notInitialized(),
27
27
  createUpstream: async (_c) => notInitialized(),
28
+ updateUpstream: async (_id, _c) => notInitialized(),
28
29
  getUpstream: async (_id) => notInitialized(),
29
30
  findUpstreamByName: async (_g, _n) => notInitialized(),
30
31
  deleteUpstream: async (_id) => notInitialized(),
31
32
  createRoute: async (_c) => notInitialized(),
33
+ updateRoute: async (_id, _c) => notInitialized(),
32
34
  getRoute: async (_id) => notInitialized(),
33
35
  findRouteByName: async (_s, _n) => notInitialized(),
34
36
  listRoutesByService: async (_s) => notInitialized(),
35
37
  deleteRoute: async (_id) => notInitialized(),
38
+ getCustomDomain: async (_id) => notInitialized(),
39
+ updateCustomDomain: async (_id, _c) => notInitialized(),
36
40
  createCustomDomain: async (_c) => notInitialized(),
37
41
  deleteCustomDomain: async (_id) => notInitialized(),
38
42
  };
@@ -364,6 +368,21 @@ const APIGW_POLL_MAX_ATTEMPTS = 120; // up to 20 minutes
364
368
  const data = (response.Result || {});
365
369
  return data.Id ?? '';
366
370
  },
371
+ updateUpstream: async (id, config) => {
372
+ await client.fetchOpenAPI({
373
+ Action: 'UpdateUpstream',
374
+ Version: '2021-03-03',
375
+ method: 'POST',
376
+ headers: { 'content-type': 'application/json' },
377
+ data: {
378
+ Id: id,
379
+ Name: config.upstreamName,
380
+ SourceType: config.sourceType,
381
+ Protocol: config.protocol ?? 'HTTP',
382
+ UpstreamSpec: { VeFaas: { FunctionId: config.functionId } },
383
+ },
384
+ });
385
+ },
367
386
  getUpstream: async (upstreamId) => {
368
387
  try {
369
388
  const response = await client.fetchOpenAPI({
@@ -520,6 +539,25 @@ const APIGW_POLL_MAX_ATTEMPTS = 120; // up to 20 minutes
520
539
  })),
521
540
  };
522
541
  },
542
+ updateRoute: async (id, config) => {
543
+ await client.fetchOpenAPI({
544
+ Action: 'UpdateRoute',
545
+ Version: '2022-11-12',
546
+ method: 'POST',
547
+ headers: { 'content-type': 'application/json' },
548
+ data: {
549
+ Id: id,
550
+ Name: config.routeName,
551
+ Enable: true,
552
+ Priority: 0,
553
+ MatchRule: {
554
+ Path: { MatchType: 'Exact', MatchContent: config.path },
555
+ Method: [config.method],
556
+ },
557
+ UpstreamList: [{ UpstreamId: config.upstreamId, Weight: 100 }],
558
+ },
559
+ });
560
+ },
523
561
  getRoute: async (routeId) => {
524
562
  try {
525
563
  const response = await client.fetchOpenAPI({
@@ -622,6 +660,48 @@ const APIGW_POLL_MAX_ATTEMPTS = 120; // up to 20 minutes
622
660
  data: { Id: routeId },
623
661
  });
624
662
  },
663
+ getCustomDomain: async (id) => {
664
+ try {
665
+ const response = await client.fetchOpenAPI({
666
+ Action: 'GetCustomDomain',
667
+ Version: '2021-03-03',
668
+ method: 'POST',
669
+ headers: { 'content-type': 'application/json' },
670
+ data: { Id: id },
671
+ });
672
+ const domain = response.Result
673
+ ?.CustomDomain;
674
+ if (!domain)
675
+ throw new Error(lang_1.lang.__('APIGW_DOMAIN_READ_INVALID', { domainId: id }));
676
+ return {
677
+ id,
678
+ serviceId: domain.ServiceId,
679
+ domainName: domain.Domain,
680
+ certificateId: domain.CertificateId,
681
+ protocol: domain.Protocol,
682
+ sslRedirect: domain.SSLRedirect,
683
+ };
684
+ }
685
+ catch (error) {
686
+ if (['NotFound', 'DomainNotFound'].includes(error.code))
687
+ return null;
688
+ throw error;
689
+ }
690
+ },
691
+ updateCustomDomain: async (id, config) => {
692
+ await client.fetchOpenAPI({
693
+ Action: 'UpdateCustomDomain',
694
+ Version: '2021-03-03',
695
+ method: 'POST',
696
+ headers: { 'content-type': 'application/json' },
697
+ data: {
698
+ Id: id,
699
+ CertificateId: config.certificateId ?? '',
700
+ Protocol: config.protocol ?? ['HTTP'],
701
+ SSLRedirect: config.sslRedirect ?? false,
702
+ },
703
+ });
704
+ },
625
705
  createCustomDomain: async (config) => {
626
706
  const response = await client.fetchOpenAPI({
627
707
  Action: 'CreateCustomDomain',
@@ -631,6 +711,8 @@ const APIGW_POLL_MAX_ATTEMPTS = 120; // up to 20 minutes
631
711
  data: {
632
712
  ServiceId: config.serviceId,
633
713
  Domain: config.domainName,
714
+ Protocol: config.protocol ?? ['HTTP'],
715
+ SSLRedirect: config.sslRedirect ?? false,
634
716
  ...(config.certificateId && { CertificateId: config.certificateId }),
635
717
  },
636
718
  });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createIamOperations = void 0;
3
+ exports.createIamOperations = exports.buildVefaasExecutionPolicy = void 0;
4
4
  const iamStatements_1 = require("../iamStatements");
5
5
  const nameBuilder_1 = require("../nameBuilder");
6
6
  const logger_1 = require("../logger");
@@ -55,13 +55,14 @@ const mapToVolcengineStatement = (stmt) => {
55
55
  }
56
56
  return result;
57
57
  };
58
- const buildExecutionPolicy = (baseline, customStatements) => {
58
+ const buildVefaasExecutionPolicy = (baseline, customStatements) => {
59
59
  const nativeBaseline = baseline
60
60
  ? baseline.map(mapToVolcengineStatement)
61
61
  : VEFAAS_EXECUTION_STATEMENTS;
62
62
  const merged = (0, iamStatements_1.mergePolicyStatements)(nativeBaseline, customStatements, mapToVolcengineStatement);
63
63
  return (0, iamStatements_1.buildPolicyDocument)(merged);
64
64
  };
65
+ exports.buildVefaasExecutionPolicy = buildVefaasExecutionPolicy;
65
66
  // TagResources expects flat numbered query params (ResourceIds.1, Tags.1.Key, ...).
66
67
  // ResourceIds.1 carries the ROLE NAME (consistent with DeleteRole using RoleName).
67
68
  const buildTagResourceQuery = (roleName, tags) => {
@@ -83,7 +84,7 @@ const createIamOperations = (iamClient) => {
83
84
  headers: { 'content-type': 'application/json' },
84
85
  query: {
85
86
  PolicyName: policyName,
86
- PolicyDocument: buildExecutionPolicy(baseline, customStatements),
87
+ PolicyDocument: (0, exports.buildVefaasExecutionPolicy)(baseline, customStatements),
87
88
  Description: `veFaaS execution policy for ${roleName}`,
88
89
  },
89
90
  });
@@ -371,6 +372,29 @@ const createIamOperations = (iamClient) => {
371
372
  throw error;
372
373
  }
373
374
  },
375
+ getPolicy: async (policyName) => {
376
+ try {
377
+ const response = await iamClient.fetchOpenAPI({
378
+ Action: 'GetPolicy',
379
+ Version: '2018-01-01',
380
+ method: 'GET',
381
+ headers: { 'content-type': 'application/json' },
382
+ query: { PolicyName: policyName, PolicyType: 'Custom' },
383
+ });
384
+ const policy = (response.Result ?? {}).Policy;
385
+ if (!policy?.PolicyDocument)
386
+ throw new Error(lang_1.lang.__('IAM_POLICY_READ_INVALID', { policyName }));
387
+ const document = JSON.parse(policy.PolicyDocument);
388
+ if (!Array.isArray(document.Statement))
389
+ throw new Error(lang_1.lang.__('IAM_POLICY_READ_INVALID', { policyName }));
390
+ return policy.PolicyDocument;
391
+ }
392
+ catch (error) {
393
+ if (error.code === 'PolicyNotExist')
394
+ return null;
395
+ throw error;
396
+ }
397
+ },
374
398
  updateRoleTrustPolicy: async (roleName, trustPolicy) => {
375
399
  const trustPolicyDocument = JSON.stringify(trustPolicy);
376
400
  try {
@@ -188,75 +188,81 @@ const createTosOperations = (client, _region) => {
188
188
  if (!client) {
189
189
  throw new Error(lang_1.lang.__('VOLCENGINE_TOS_CLIENT_NOT_INITIALIZED'));
190
190
  }
191
- try {
192
- const response = await client.fetchOpenAPI({
193
- Action: 'GetBucketInfo',
194
- Version: '2018-08-01',
195
- method: 'GET',
196
- query: {
197
- Bucket: bucketName,
198
- },
199
- });
200
- const result = (response.Result || {});
201
- const bucketData = (result.BucketInfo || {});
202
- let websiteConfig;
191
+ const response = await (async () => {
203
192
  try {
204
- const websiteResponse = await client.fetchOpenAPI({
205
- Action: 'GetBucketWebsite',
193
+ return await client.fetchOpenAPI({
194
+ Action: 'GetBucketInfo',
206
195
  Version: '2018-08-01',
207
196
  method: 'GET',
208
197
  query: {
209
198
  Bucket: bucketName,
210
199
  },
211
200
  });
212
- const websiteResult = (websiteResponse.Result || {});
213
- if (websiteResult.IndexDocument) {
214
- const indexDoc = websiteResult.IndexDocument;
215
- websiteConfig = {
216
- indexDocument: indexDoc.Suffix,
217
- };
218
- if (websiteResult.ErrorDocument) {
219
- const errorDoc = websiteResult.ErrorDocument;
220
- websiteConfig.errorDocument = errorDoc.Key;
221
- }
222
- }
223
201
  }
224
- catch {
225
- // Website config may not exist
226
- }
227
- let tags;
228
- try {
229
- const taggingResponse = await client.fetchOpenAPI({
230
- Action: 'GetBucketTagging',
231
- Version: '2018-08-01',
232
- method: 'GET',
233
- query: {
234
- Bucket: bucketName,
235
- },
236
- });
237
- const taggingResult = (taggingResponse.Result || {});
238
- const tagSet = (taggingResult.TagSet || {});
239
- const tagList = (tagSet.Tags || []);
240
- tags = tagList.map((t) => ({ Key: t.Key, Value: t.Value }));
202
+ catch (error) {
203
+ if (error &&
204
+ typeof error === 'object' &&
205
+ 'code' in error &&
206
+ (error.code === 'NoSuchBucket' || error.code === 'ResourceNotFound')) {
207
+ return null;
208
+ }
209
+ throw error;
241
210
  }
242
- catch {
243
- // Bucket tagging may not be configured
211
+ })();
212
+ if (response === null)
213
+ return null;
214
+ const result = (response.Result || {});
215
+ const bucketData = (result.BucketInfo || {});
216
+ let websiteConfig = null;
217
+ try {
218
+ const websiteResponse = await client.fetchOpenAPI({
219
+ Action: 'GetBucketWebsite',
220
+ Version: '2018-08-01',
221
+ method: 'GET',
222
+ query: {
223
+ Bucket: bucketName,
224
+ },
225
+ });
226
+ const websiteResult = (websiteResponse.Result || {});
227
+ if (websiteResult.IndexDocument) {
228
+ const indexDoc = websiteResult.IndexDocument;
229
+ websiteConfig = {
230
+ indexDocument: indexDoc.Suffix,
231
+ };
232
+ if (websiteResult.ErrorDocument) {
233
+ const errorDoc = websiteResult.ErrorDocument;
234
+ websiteConfig.errorDocument = errorDoc.Key;
235
+ }
244
236
  }
245
- return {
246
- ...mapBucketInfo(bucketName, bucketData),
247
- websiteConfig,
248
- Tags: tags,
249
- };
250
237
  }
251
238
  catch (error) {
252
- if (error &&
253
- typeof error === 'object' &&
254
- 'code' in error &&
255
- (error.code === 'NoSuchBucket' || error.code === 'ResourceNotFound')) {
256
- return null;
257
- }
258
- throw error;
239
+ const code = error?.code;
240
+ if (code !== 'NoSuchWebsiteConfiguration' && code !== 'NoSuchConfiguration')
241
+ throw error;
242
+ }
243
+ let tags;
244
+ try {
245
+ const taggingResponse = await client.fetchOpenAPI({
246
+ Action: 'GetBucketTagging',
247
+ Version: '2018-08-01',
248
+ method: 'GET',
249
+ query: {
250
+ Bucket: bucketName,
251
+ },
252
+ });
253
+ const taggingResult = (taggingResponse.Result || {});
254
+ const tagSet = (taggingResult.TagSet || {});
255
+ const tagList = (tagSet.Tags || []);
256
+ tags = tagList.map((t) => ({ Key: t.Key, Value: t.Value }));
257
+ }
258
+ catch {
259
+ // Bucket tagging may not be configured
259
260
  }
261
+ return {
262
+ ...mapBucketInfo(bucketName, bucketData),
263
+ websiteConfig,
264
+ Tags: tags,
265
+ };
260
266
  },
261
267
  updateBucketAcl: async (bucketName, acl) => {
262
268
  if (!client) {
@@ -598,6 +598,51 @@ const createVefaasOperations = (client) => {
598
598
  lastModifiedTime: fn.LastUpdateTime,
599
599
  }));
600
600
  },
601
+ // veFaaS timer triggers (issue #258): CreateTrigger/ListTriggers/
602
+ // DeleteTrigger of the veFaaS OpenAPI (Version 2024-06-06). A timer
603
+ // trigger binds one function via FunctionId; the config travels as a JSON
604
+ // `Source` string with SourceType 'Timer' — unix 5-field crontab
605
+ // (translation handled in common/siCron, which rejects non-zero seconds).
606
+ createTrigger: async (params) => {
607
+ await client.fetchOpenAPI({
608
+ Action: 'CreateTrigger',
609
+ Version: '2024-06-06',
610
+ method: 'POST',
611
+ headers: { 'content-type': 'application/json' },
612
+ data: {
613
+ FunctionId: params.functionId,
614
+ Name: params.name,
615
+ SourceType: 'Timer',
616
+ Source: JSON.stringify(params.source),
617
+ },
618
+ });
619
+ },
620
+ listTriggers: async (functionId) => {
621
+ const response = await client.fetchOpenAPI({
622
+ Action: 'ListTriggers',
623
+ Version: '2024-06-06',
624
+ method: 'POST',
625
+ headers: { 'content-type': 'application/json' },
626
+ data: { FunctionId: functionId },
627
+ });
628
+ const result = (response.Result || {});
629
+ const items = (result.Triggers ?? result.Items ?? []);
630
+ return items.map((item) => ({
631
+ id: item.Id ?? item.TriggerId,
632
+ name: item.Name ?? item.TriggerName,
633
+ sourceType: item.SourceType,
634
+ source: item.Source,
635
+ }));
636
+ },
637
+ deleteTrigger: async (functionId, triggerId) => {
638
+ await client.fetchOpenAPI({
639
+ Action: 'DeleteTrigger',
640
+ Version: '2024-06-06',
641
+ method: 'POST',
642
+ headers: { 'content-type': 'application/json' },
643
+ data: { FunctionId: functionId, TriggerId: triggerId },
644
+ });
645
+ },
601
646
  };
602
647
  return operations;
603
648
  };
@@ -2,6 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.en = void 0;
4
4
  exports.en = {
5
+ PLAN_SENSITIVE_VALUE: '(sensitive)',
6
+ PLAN_NAS_NETWORK_REQUIRED: 'NAS storage on {{logicalId}} needs a declared VPC network or recorded mount targets. Planning stopped before creating any resources.',
7
+ APIGW_DOMAIN_READ_INVALID: 'Invalid domain response for: {{domainId}}',
8
+ PLAN_DRIFT_EVENT_DOMAIN: 'Gateway domain or certificate differs from the requested configuration or is missing',
9
+ PLAN_DRIFT_HTTP_TRIGGER: 'HTTP trigger differs from the requested configuration or is missing',
10
+ PLAN_DRIFT_FUNCTION_DOMAIN: 'Function domain differs from the requested configuration or is missing',
11
+ PLAN_REPLACEMENT_REQUIRED: 'Changes to {{fields}} on {{logicalId}} require resource replacement. Automatic replacement is not supported; explicitly migrate or recreate the resource.',
12
+ PLAN_UPDATE_NOT_SUPPORTED: 'Cannot update {{fields}} on {{logicalId}}: the provider update implementation does not support these fields. No changes have been applied.',
13
+ PLAN_STATE_ONLY: '{{logicalId}} already matches the cloud; only saved intent will be updated.',
5
14
  // Validation messages
6
15
  VALIDATING_YAML: 'Validating yaml...',
7
16
  YAML_VALID: 'Yaml is valid! 🎉',
@@ -49,6 +58,10 @@ exports.en = {
49
58
  LOCAL_GATEWAY_ERROR: 'Local gateway error',
50
59
  ERROR_STOPPING_LOCAL_SERVER: 'Error stopping localServer',
51
60
  RUN_LOCAL_STARTING: 'run-local starting: stage={{stage}} debug={{debug}} watch={{watch}}',
61
+ LOCAL_TIMER_SCHEDULED: "Local timer '{{triggerName}}' scheduled for function '{{functionName}}' (cron: {{cron}}, UTC)",
62
+ LOCAL_TIMER_FIRED: "Local timer '{{triggerName}}' firing function '{{functionName}}'...",
63
+ LOCAL_TIMER_DISABLED: "Local timer '{{triggerName}}' is disabled (enable: false), skipping schedule",
64
+ LOCAL_TIMER_INVALID_CRON: "Local timer '{{triggerName}}' has invalid cron '{{cron}}', skipping schedule",
52
65
  // Function execution
53
66
  FUNCTION_REQUEST_RECEIVED: 'Function request received by local server -> {{method}} {{identifier}} ',
54
67
  INVOKING_WORKER_WITH_EVENT_TYPE: 'Invoking worker with event type: {{eventType}} and context',
@@ -117,7 +130,7 @@ exports.en = {
117
130
  PLAN_COMPUTED_VALUE: '(known after deploy)',
118
131
  PLAN_REVERT_ANNOTATION: '(changed in the cloud, will be restored to config)',
119
132
  PLAN_DRIFTED_MARKER: '(drifted — cloud changed outside of this config, will be reconciled)',
120
- PLAN_LIVE_READ_FAILED: 'Failed to read live state for {{logicalId}}; planning a create instead: {{error}}',
133
+ PLAN_LIVE_READ_FAILED: 'Failed to read live state for {{logicalId}}; planning stopped: {{error}}',
121
134
  PLAN_DRIFT_ROLE_MISSING: 'IAM role missing in the cloud',
122
135
  PLAN_DRIFT_ROLE_POLICY: 'IAM role policy changed in the cloud',
123
136
  PLAN_DRIFT_LOGSTORE: 'function log resources changed in the cloud',
@@ -246,8 +259,8 @@ exports.en = {
246
259
  SHARED_SLS_PROJECT_ADOPTED: 'Adopting existing shared SLS project {{projectName}} owned by this app',
247
260
  REFRESH_CACHE_HIT: 'Refresh read cache hit: {{key}}',
248
261
  PLAN_FUNCTION_ROLE_MISSING: 'Function {{functionName}} role {{roleName}} is missing in the provider; it will be recreated and rebound on deploy',
249
- PLAN_FUNCTION_ROLE_PROBE_FAILED: 'Live role policy check for function {{functionName}} (role {{roleName}}) failed: {{error}}; skipping role drift detection for this plan',
250
- PLAN_FUNCTION_NESTED_PROBE_FAILED: 'Nested resource probe for function {{functionName}} failed: {{error}}; skipping nested drift detection for this plan',
262
+ PLAN_FUNCTION_ROLE_PROBE_FAILED: 'Live role policy check for function {{functionName}} (role {{roleName}}) failed: {{error}}; planning stopped',
263
+ PLAN_FUNCTION_NESTED_PROBE_FAILED: 'Nested resource probe for function {{functionName}} failed: {{error}}; planning stopped',
251
264
  NESTED_LOGSTORE_RECREATED: 'Logstore {{logstoreName}} was deleted out-of-band; recreating it',
252
265
  NESTED_LOGSTORE_UPDATED: 'Logstore {{logstoreName}} attributes drifted; updating to match si defaults',
253
266
  NESTED_TLS_TOPIC_UPDATED: 'TLS topic {{topicId}} ttl drifted; updating to match si defaults',
@@ -876,6 +889,37 @@ exports.en = {
876
889
  EVENT_FLUSH_FAILED: 'Failed to flush deployment events for {{deploymentId}} ({{count}} events): {{error}}',
877
890
  EVENT_REPLAY_FAILED: 'Failed to replay event queue file {{file}}: {{error}}',
878
891
  INVALID_HTTP_TRIGGER_AUTH_TYPE: "Invalid HTTP trigger auth_type '{{authType}}'; must be 'public' or 'iam'",
892
+ // Timer trigger messages (issue #258)
893
+ TIMER_TRIGGER_NAME_REQUIRED: "Timer trigger on function '{{functionName}}' requires 'name'",
894
+ TIMER_TRIGGER_CRON_REQUIRED: "Timer trigger '{{name}}' requires 'cron'",
895
+ TIMER_TRIGGER_DUPLICATE_NAME: "Duplicate timer trigger name '{{name}}' on function '{{functionName}}'",
896
+ TIMER_TRIGGER_LIMIT_EXCEEDED: "Function '{{functionName}}' has {{count}} timer triggers; provider {{provider}} allows at most {{max}}",
897
+ SEMANTIC_TIMER_CRON_INVALID: "Timer trigger '{{name}}' on function '{{functionName}}' has invalid cron '{{cron}}': {{reason}}",
898
+ TIMER_TRIGGER_NOT_SUPPORTED_PROVIDER: "Timer triggers are not supported for provider '{{provider}}'",
899
+ TIMER_TRIGGER_PAYLOAD_NOT_SUPPORTED: "Timer trigger '{{name}}' on provider {{provider}} does not support 'payload'",
900
+ CREATING_TIMER_TRIGGER: "Creating timer trigger '{{triggerName}}' for function '{{functionName}}'...",
901
+ TIMER_TRIGGER_CREATED: "Timer trigger '{{triggerName}}' created for function '{{functionName}}'",
902
+ UPDATING_TIMER_TRIGGER: "Recreating timer trigger '{{triggerName}}' for function '{{functionName}}'...",
903
+ DELETING_TIMER_TRIGGER: "Deleting timer trigger '{{triggerName}}' for function '{{functionName}}'...",
904
+ TIMER_TRIGGER_DELETED: "Timer trigger '{{triggerName}}' deleted",
905
+ TIMER_TRIGGER_NOT_FOUND: "Timer trigger '{{triggerName}}' not found in provider, skipping delete",
906
+ TIMER_TRIGGER_ALREADY_ATTACHED: "Timer trigger '{{triggerName}}' is already attached to function '{{functionName}}', skipping create",
907
+ PLAN_DRIFT_TIMER_TRIGGER: 'Timer triggers differ from the requested configuration',
908
+ PLAN_TIMER_TRIGGER_PROBE_FAILED: "Failed to probe timer triggers for function '{{functionName}}': {{error}}",
909
+ // si-cron messages (issue #258)
910
+ SI_CRON_EMPTY: 'si-cron expression is empty',
911
+ SI_CRON_WRONG_FIELD_COUNT: 'expects 5 fields (minute hour day month weekday), 6 fields with a seconds prefix, or @every <duration>; got {{count}}',
912
+ SI_CRON_FIELD_INVALID: "field '{{field}}' has invalid value '{{value}}'",
913
+ SI_CRON_FIELD_EMPTY: "field '{{field}}' is empty",
914
+ SI_CRON_FIELD_RANGE: "field '{{field}}' value '{{value}}' out of range {{min}}-{{max}}",
915
+ SI_CRON_STEP_INVALID: "field '{{field}}' has invalid step '{{step}}'",
916
+ SI_CRON_RANGE_DESCENDING: "field '{{field}}' has descending range '{{range}}'",
917
+ SI_CRON_EVERY_INVALID: "'@every {{duration}}' is not a valid duration; use forms like '30s', '5m', '1h', '1d'",
918
+ SI_CRON_EVERY_NOT_EXPRESSIBLE: 'this @every interval cannot be expressed as a {{dialect}} cron; use durations that divide evenly (15s, 30s, 1m, 5m, 15m, 30m, 1h, 2h, 6h, 12h, 1d)',
919
+ SI_CRON_SHIFT_UNSUPPORTED: "cron '{{cron}}' cannot be shifted to UTC+8 without changing which dates fire; avoid day-of-month/day-of-week schedules with UTC hours >= 16 that cross a month boundary",
920
+ SI_CRON_SECONDS_UNSUPPORTED: "cron '{{cron}}' has non-zero seconds which a 5-field crontab provider does not support",
921
+ // Nested live-repair failures (issue #234 executor reconciles)
922
+ NESTED_REPAIR_FAILED: "Failed to repair nested resource '{{resource}}': {{error}}",
879
923
  // ===== Issue #251: previously hardcoded messages (now i18n) =====
880
924
  UNSUPPORTED_PROVIDER: 'Unsupported provider: {{provider}}',
881
925
  FORCE_UNLOCK_NO_LOCATION_MODE: 'Not supported in no-location mode',
@@ -885,6 +929,7 @@ exports.en = {
885
929
  SHOW_NO_RESOURCES: 'No resources found in state.',
886
930
  SHOW_STATE_LOCATION: 'State location: {{stateLocation}}',
887
931
  SHOW_BACKEND_REMOTE: 'Backend: Remote',
932
+ SHOW_BACKEND_SAAS: 'Console (SaaS state)',
888
933
  SHOW_DEPLOY_HINT: 'To deploy resources, run: si deploy',
889
934
  SHOW_HEADER_DEPLOYED: 'DEPLOYED RESOURCES',
890
935
  SHOW_CATEGORY_HEADER: '📦 {{label}}',
@@ -980,11 +1025,26 @@ exports.en = {
980
1025
  OTS_ATTRIBUTE_NOT_FOUND: 'Attribute not found for key: {{key}}',
981
1026
  LOCAL_HANDLER_NOT_FOUND: 'Handler "{{handlerMethod}}" not found or is not a function in {{handlerPath}}',
982
1027
  LOCAL_EXECUTION_TIMEOUT: 'Function execution timed out after {{timeoutMs}}ms',
1028
+ LOCAL_FUNCTION_NOT_FOUND: 'Function not found',
1029
+ LOCAL_FUNCTION_CODE_MISSING: 'Function code configuration not found',
1030
+ LOCAL_FUNCTION_EXECUTION_FAILED: 'Function execution failed',
1031
+ LOCAL_HTTP_PROVIDER_UNSUPPORTED: 'Local HTTP invocation is not supported for provider {{provider}}',
1032
+ LOCAL_VOLCENGINE_MODE_UNSUPPORTED: 'Local veFaaS HTTP invocation supports node14/v1 and node20/v1 code packages only (function: {{functionName}}). Containers, native runtimes and other languages are not simulated.',
1033
+ LOCAL_VOLCENGINE_BINARY_UNSUPPORTED: 'Local veFaaS HTTP invocation supports UTF-8 request bodies only. Binary bodies containing invalid UTF-8 are not simulated; no base64 event contract is assumed.',
1034
+ LOCAL_VOLCENGINE_INVALID_RESPONSE: 'Invalid local veFaaS response: return an object with an optional integer statusCode (200-599), string-valued headers and a string body. Binary responses are not simulated.',
1035
+ LOCAL_EVENT_TYPE_UNSUPPORTED: 'Local event endpoints support API_GATEWAY triggers only.',
1036
+ LOCAL_SCF_EVENT_UNSUPPORTED: 'Local SCF simulation covers the function-owned function URL, not API Gateway events (no Tencent API Gateway is deployed). Invoke the function URL at /si_functions/<function-key>/<path>.',
1037
+ LOCAL_SCF_MODE_UNSUPPORTED: 'Local SCF HTTP invocation supports {{runtimes}} code packages only (function: {{functionName}}). Containers, Web Functions and other languages are not simulated.',
1038
+ LOCAL_SCF_BINARY_REQUEST_UNSUPPORTED: 'Local SCF HTTP invocation supports UTF-8 request bodies only. The function-URL event carries no isBase64Encoded field, so binary bodies are not simulated.',
1039
+ LOCAL_SCF_BINARY_RESPONSE_UNSUPPORTED: 'Local SCF responses do not support binary bodies: the function-URL response carries no isBase64Encoded field, so isBase64Encoded responses are not simulated.',
1040
+ LOCAL_SCF_INVALID_RESPONSE: 'Invalid local SCF response: return a string or JSON object, or an object with an optional integer statusCode (200-599), string-valued headers and a string body.',
983
1041
  LOCAL_PORT_CLOSED: 'Port closed before receiving response',
984
1042
  LOCAL_WORKER_EXITED: 'Worker stopped with exit code {{code}}',
985
1043
  REFRESH_STATE_BUCKET: 'Failed to refresh state for bucket: {{name}}',
986
1044
  RESOURCE_SPACE_ID_NOT_FOUND: 'Space ID not found in state for {{logicalId}}',
987
1045
  REFRESH_STATE_ES_SPACE: 'Failed to refresh state for ES space: {{spaceId}}',
1046
+ IAM_POLICY_READ_INVALID: 'Invalid policy document returned for: {{policyName}}',
1047
+ SCF_HTTP_TRIGGER_ID_UNAVAILABLE: 'Cannot record the cloud-assigned HTTP trigger identity for function: {{functionName}}',
988
1048
  SCF_HTTP_TRIGGER_ALREADY_ATTACHED: 'HTTP trigger {{triggerName}} already attached to {{functionName}}, skipping creation',
989
1049
  SCF_HTTP_TRIGGER_ALREADY_EXISTS: 'HTTP trigger {{triggerName}} already exists on {{functionName}}, continuing: {{error}}',
990
1050
  SCF_HANDLER_IMMUTABLE: 'Handler is immutable in Tencent SCF and cannot be changed on update ({{oldHandler}} -> {{newHandler}}). Delete and recreate the function instead.',
@@ -1040,4 +1100,11 @@ exports.en = {
1040
1100
  OPT_PARAMETER: 'override parameters',
1041
1101
  OPT_DEBUG: 'enable debug mode',
1042
1102
  OPT_WATCH: 'enable file watch',
1103
+ // ===== Issue #250: agent-friendly CLI surface =====
1104
+ CMD_SCHEMA_DESC: 'export the IaC JSON Schema used for validation (draft-07, self-contained)',
1105
+ OPT_SCHEMA_OUTPUT: 'write the JSON Schema to a file instead of stdout',
1106
+ OPT_JSON: 'output the result as machine-readable JSON to stdout (logs stay on stderr)',
1107
+ OPT_NO_COLOR: 'disable colored output (also honors the NO_COLOR environment variable)',
1108
+ SCHEMA_WRITTEN_TO: 'JSON Schema written to: {{path}}',
1109
+ ERROR_CODE: 'Error code: {{code}}',
1043
1110
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lang = void 0;
3
+ exports.lang = exports.lookupErrorCode = exports.hasLangKey = void 0;
4
4
  const child_process_1 = require("child_process");
5
5
  const i18n_1 = require("i18n");
6
6
  const en_1 = require("./en");
@@ -39,3 +39,38 @@ const lang = new i18n_1.I18n({
39
39
  objectNotation: true,
40
40
  });
41
41
  exports.lang = lang;
42
+ let templateIndex = null;
43
+ const buildTemplateIndex = () => [...Object.entries(en_1.en), ...Object.entries(zh_CN_1.zhCN)].flatMap(([key, value]) => typeof value === 'string' ? [{ key, segments: value.split(/{{[^}]*}}/g) }] : []);
44
+ const matchTemplate = (message, segments) => {
45
+ if (segments.length === 1) {
46
+ return message === segments[0];
47
+ }
48
+ let rest = message;
49
+ for (let i = 0; i < segments.length; i++) {
50
+ const segment = segments[i];
51
+ if (i === 0) {
52
+ if (!rest.startsWith(segment))
53
+ return false;
54
+ rest = rest.slice(segment.length);
55
+ continue;
56
+ }
57
+ if (i === segments.length - 1) {
58
+ return rest.endsWith(segment);
59
+ }
60
+ const at = rest.indexOf(segment);
61
+ if (at < 0)
62
+ return false;
63
+ rest = rest.slice(at + segment.length);
64
+ }
65
+ return true;
66
+ };
67
+ const langKeySet = () => new Set(Object.keys({ ...en_1.en, ...zh_CN_1.zhCN }));
68
+ const hasLangKey = (key) => langKeySet().has(key);
69
+ exports.hasLangKey = hasLangKey;
70
+ const lookupErrorCode = (message) => {
71
+ if (!message)
72
+ return undefined;
73
+ templateIndex = templateIndex ?? buildTemplateIndex();
74
+ return templateIndex.find((template) => matchTemplate(message, template.segments))?.key;
75
+ };
76
+ exports.lookupErrorCode = lookupErrorCode;