@geek-fun/serverlessinsight 0.8.2 → 0.8.4

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 +15 -0
  2. package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +33 -0
  3. package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +359 -0
  4. package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +15 -0
  5. package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +154 -0
  6. package/.serverlessinsight/state-insight-volc-destroy-app-insight-volc-destroy.json.backup +1 -0
  7. package/README.md +26 -18
  8. package/README.zh-CN.md +19 -6
  9. package/dist/package.json +5 -2
  10. package/dist/src/commands/deploy.js +87 -4
  11. package/dist/src/commands/destroy.js +61 -10
  12. package/dist/src/commands/forceUnlock.js +8 -0
  13. package/dist/src/commands/index.js +34 -2
  14. package/dist/src/commands/login.js +195 -0
  15. package/dist/src/commands/logout.js +17 -0
  16. package/dist/src/commands/show.js +15 -7
  17. package/dist/src/commands/whoami.js +20 -0
  18. package/dist/src/common/aliyunClient/apigwOperations.js +363 -30
  19. package/dist/src/common/aliyunClient/esOperations.js +43 -29
  20. package/dist/src/common/aliyunClient/fc3Operations.js +481 -207
  21. package/dist/src/common/aliyunClient/ossOperations.js +165 -13
  22. package/dist/src/common/aliyunClient/rdsOperations.js +143 -39
  23. package/dist/src/common/aliyunClient/slsOperations.js +90 -28
  24. package/dist/src/common/aliyunClient/tablestoreOperations.js +25 -22
  25. package/dist/src/common/apiClient.js +102 -0
  26. package/dist/src/common/constants.js +13 -4
  27. package/dist/src/common/credentialStore.js +94 -0
  28. package/dist/src/common/credentials.js +2 -0
  29. package/dist/src/common/eventQueue.js +208 -0
  30. package/dist/src/common/hashUtils.js +87 -11
  31. package/dist/src/common/imsClient.js +1 -0
  32. package/dist/src/common/index.js +3 -0
  33. package/dist/src/common/lockManager.js +61 -54
  34. package/dist/src/common/logger.js +2 -0
  35. package/dist/src/common/polling.js +54 -0
  36. package/dist/src/common/reportResourceEvent.js +8 -0
  37. package/dist/src/common/runtimeMapper.js +11 -12
  38. package/dist/src/common/stateBackend/index.js +10 -1
  39. package/dist/src/common/stateBackend/localStateBackend.js +4 -1
  40. package/dist/src/common/stateBackend/remoteStateBackend.js +10 -4
  41. package/dist/src/common/stateBackend/saasStateBackend.js +266 -0
  42. package/dist/src/common/stateManager.js +186 -14
  43. package/dist/src/common/tencentClient/clsOperations.js +137 -0
  44. package/dist/src/common/tencentClient/cosOperations.js +180 -3
  45. package/dist/src/common/tencentClient/esOperations.js +110 -46
  46. package/dist/src/common/tencentClient/index.js +43 -2
  47. package/dist/src/common/tencentClient/scfOperations.js +266 -133
  48. package/dist/src/common/tencentClient/tdsqlcClusterMapper.js +81 -0
  49. package/dist/src/common/tencentClient/tdsqlcOperations.js +93 -99
  50. package/dist/src/common/triggerMapper.js +36 -0
  51. package/dist/src/common/volcengineClient/apigwOperations.js +539 -159
  52. package/dist/src/common/volcengineClient/iamOperations.js +91 -48
  53. package/dist/src/common/volcengineClient/index.js +46 -21
  54. package/dist/src/common/volcengineClient/stsOperations.js +32 -0
  55. package/dist/src/common/volcengineClient/tlsOperations.js +305 -171
  56. package/dist/src/common/volcengineClient/tosOperations.js +78 -19
  57. package/dist/src/common/volcengineClient/vefaasOperations.js +272 -54
  58. package/dist/src/lang/en.js +107 -1
  59. package/dist/src/lang/zh-CN.js +107 -1
  60. package/dist/src/parser/eventParser.js +2 -0
  61. package/dist/src/parser/functionParser.js +96 -65
  62. package/dist/src/parser/index.js +7 -4
  63. package/dist/src/stack/aliyunStack/apigwExecutor.js +39 -1
  64. package/dist/src/stack/aliyunStack/apigwPlanner.js +16 -10
  65. package/dist/src/stack/aliyunStack/apigwResource.js +334 -125
  66. package/dist/src/stack/aliyunStack/apigwTypes.js +35 -4
  67. package/dist/src/stack/aliyunStack/databaseExecutor.js +39 -1
  68. package/dist/src/stack/aliyunStack/databasePlanner.js +13 -1
  69. package/dist/src/stack/aliyunStack/databaseResource.js +135 -40
  70. package/dist/src/stack/aliyunStack/deployer.js +2 -2
  71. package/dist/src/stack/aliyunStack/destroyer.js +27 -2
  72. package/dist/src/stack/aliyunStack/fc3Executor.js +25 -2
  73. package/dist/src/stack/aliyunStack/fc3Planner.js +11 -1
  74. package/dist/src/stack/aliyunStack/fc3Resource.js +416 -94
  75. package/dist/src/stack/aliyunStack/ossExecutor.js +39 -1
  76. package/dist/src/stack/aliyunStack/ossPlanner.js +15 -1
  77. package/dist/src/stack/aliyunStack/ossResource.js +267 -219
  78. package/dist/src/stack/aliyunStack/sharedLogProject.js +137 -0
  79. package/dist/src/stack/aliyunStack/tablestoreExecutor.js +39 -1
  80. package/dist/src/stack/aliyunStack/tablestorePlanner.js +13 -1
  81. package/dist/src/stack/aliyunStack/tablestoreResource.js +54 -20
  82. package/dist/src/stack/alreadyExists.js +26 -0
  83. package/dist/src/stack/ownershipTag.js +58 -0
  84. package/dist/src/stack/rfsStack/index.js +3 -1
  85. package/dist/src/stack/scfStack/cosExecutor.js +39 -1
  86. package/dist/src/stack/scfStack/cosPlanner.js +11 -1
  87. package/dist/src/stack/scfStack/cosResource.js +167 -64
  88. package/dist/src/stack/scfStack/deployer.js +2 -2
  89. package/dist/src/stack/scfStack/destroyer.js +15 -2
  90. package/dist/src/stack/scfStack/esServerlessExecutor.js +39 -1
  91. package/dist/src/stack/scfStack/esServerlessPlanner.js +11 -1
  92. package/dist/src/stack/scfStack/esServerlessResource.js +88 -23
  93. package/dist/src/stack/scfStack/scfExecutor.js +39 -1
  94. package/dist/src/stack/scfStack/scfPlanner.js +21 -3
  95. package/dist/src/stack/scfStack/scfResource.js +686 -24
  96. package/dist/src/stack/scfStack/scfTypes.js +6 -0
  97. package/dist/src/stack/scfStack/sharedLogset.js +126 -0
  98. package/dist/src/stack/scfStack/tdsqlcExecutor.js +39 -1
  99. package/dist/src/stack/scfStack/tdsqlcPlanner.js +12 -1
  100. package/dist/src/stack/scfStack/tdsqlcResource.js +95 -16
  101. package/dist/src/stack/scfStack/tdsqlcTypes.js +5 -1
  102. package/dist/src/stack/volcengineStack/apigwExecutor.js +39 -1
  103. package/dist/src/stack/volcengineStack/apigwPlanner.js +25 -53
  104. package/dist/src/stack/volcengineStack/apigwResource.js +434 -222
  105. package/dist/src/stack/volcengineStack/apigwTypes.js +85 -66
  106. package/dist/src/stack/volcengineStack/deployer.js +49 -14
  107. package/dist/src/stack/volcengineStack/destroyer.js +13 -1
  108. package/dist/src/stack/volcengineStack/index.js +1 -2
  109. package/dist/src/stack/volcengineStack/sharedLogProject.js +190 -0
  110. package/dist/src/stack/volcengineStack/tosExecutor.js +25 -2
  111. package/dist/src/stack/volcengineStack/tosPlanner.js +11 -1
  112. package/dist/src/stack/volcengineStack/tosResource.js +82 -27
  113. package/dist/src/stack/volcengineStack/tosTypes.js +12 -0
  114. package/dist/src/stack/volcengineStack/vefaasExecutor.js +25 -2
  115. package/dist/src/stack/volcengineStack/vefaasPlanner.js +78 -2
  116. package/dist/src/stack/volcengineStack/vefaasResource.js +194 -144
  117. package/dist/src/stack/volcengineStack/vefaasTypes.js +1 -3
  118. package/dist/src/types/domains/backend.js +1 -0
  119. package/dist/src/types/domains/state.js +32 -1
  120. package/dist/src/validator/eventSchema.js +10 -0
  121. package/dist/src/validator/functionSchema.js +37 -12
  122. package/dist/src/validator/iacSchema.js +1 -0
  123. package/dist/tsconfig.tsbuildinfo +1 -1
  124. package/package.json +5 -2
@@ -36,6 +36,37 @@ const parseXmlResponse = (xml, tagName) => {
36
36
  return null;
37
37
  }
38
38
  };
39
+ // GetBucketReplication XML → list of BucketReplicationRule. The ali-oss SDK has
40
+ // no typed getBucketReplication, so we parse the raw XML response instead.
41
+ const parseReplicationRules = (xml) => {
42
+ const ruleRegex = /<Rule>([\s\S]*?)<\/Rule>/g;
43
+ const rules = [];
44
+ let ruleMatch;
45
+ while ((ruleMatch = ruleRegex.exec(xml)) !== null) {
46
+ const ruleXml = ruleMatch[1];
47
+ const read = (tag) => {
48
+ const m = new RegExp(`<${tag}>([\\s\\S]*?)<\\/${tag}>`).exec(ruleXml);
49
+ return m ? m[1].trim() : undefined;
50
+ };
51
+ const destinationXml = /<Destination>([\s\S]*?)<\/Destination>/.exec(ruleXml);
52
+ const readDest = (tag) => {
53
+ if (!destinationXml)
54
+ return undefined;
55
+ const m = new RegExp(`<${tag}>([\\s\\S]*?)<\\/${tag}>`).exec(destinationXml[1]);
56
+ return m ? m[1].trim() : undefined;
57
+ };
58
+ rules.push({
59
+ id: read('ID'),
60
+ status: read('Status'),
61
+ prefix: read('Prefix'),
62
+ destination: {
63
+ bucket: readDest('Bucket'),
64
+ storageClass: readDest('StorageClass'),
65
+ },
66
+ });
67
+ }
68
+ return rules;
69
+ };
39
70
  /* istanbul ignore next */ const createOssOperations = (ossClient, region, dnsOps) => {
40
71
  const useBucket = (bucketName) => {
41
72
  ossClient.useBucket(bucketName);
@@ -481,12 +512,21 @@ const parseXmlResponse = (xml, tagName) => {
481
512
  }
482
513
  }
483
514
  };
484
- return {
515
+ const operations = {
485
516
  createBucket: async (config) => {
517
+ const putBucketOptions = {};
486
518
  if (config.storageClass) {
487
- await ossClient.putBucket(config.bucketName, {
488
- storageClass: config.storageClass,
489
- });
519
+ putBucketOptions.storageClass = config.storageClass;
520
+ }
521
+ if (config.Tags && config.Tags.length > 0) {
522
+ // OSS accepts bucket tags at create time via the x-oss-bucket-tagging
523
+ // header: URL-encoded `key1=value1&key2=value2`.
524
+ putBucketOptions.headers = {
525
+ 'x-oss-bucket-tagging': config.Tags.map((tag) => `${encodeURIComponent(tag.Key)}=${encodeURIComponent(tag.Value)}`).join('&'),
526
+ };
527
+ }
528
+ if (putBucketOptions.storageClass || putBucketOptions.headers) {
529
+ await ossClient.putBucket(config.bucketName, putBucketOptions);
490
530
  }
491
531
  else {
492
532
  await ossClient.putBucket(config.bucketName);
@@ -593,25 +633,130 @@ const parseXmlResponse = (xml, tagName) => {
593
633
  try {
594
634
  const lifecycleResult = await ossClient.getBucketLifecycle(bucketName);
595
635
  if (lifecycleResult.rules && lifecycleResult.rules.length > 0) {
596
- lifecycleRules = lifecycleResult.rules.map((rule) => ({
597
- id: rule.id,
598
- status: rule.status,
599
- prefix: rule.prefix,
600
- expiration: rule.days
636
+ lifecycleRules = lifecycleResult.rules.map((rule) => {
637
+ const rawRule = rule;
638
+ const rawTransition = Array.isArray(rawRule.transition)
639
+ ? rawRule.transition[0]
640
+ : rawRule.transition;
641
+ const transition = (rawTransition ?? undefined);
642
+ const expirationDays = rawRule.expiration?.days ?? rule.days;
643
+ const expirationDate = rawRule.expiration?.date ?? rule.date;
644
+ const expiredObjectDeleteMarker = rawRule.expiration?.expiredObjectDeleteMarker;
645
+ const expiration = expirationDays !== undefined
601
646
  ? {
602
- days: typeof rule.days === 'number' ? rule.days : parseInt(rule.days, 10),
647
+ days: typeof expirationDays === 'number'
648
+ ? expirationDays
649
+ : parseInt(expirationDays, 10),
650
+ ...(expiredObjectDeleteMarker ? { expiredObjectDeleteMarker: true } : {}),
603
651
  }
604
- : rule.date
652
+ : expirationDate
653
+ ? {
654
+ date: expirationDate,
655
+ ...(expiredObjectDeleteMarker ? { expiredObjectDeleteMarker: true } : {}),
656
+ }
657
+ : expiredObjectDeleteMarker
658
+ ? { expiredObjectDeleteMarker: true }
659
+ : undefined;
660
+ return {
661
+ id: rule.id,
662
+ status: rule.status,
663
+ prefix: rule.prefix,
664
+ expiration,
665
+ transition: transition
605
666
  ? {
606
- date: rule.date,
667
+ days: typeof transition.days === 'number'
668
+ ? transition.days
669
+ : transition.days !== undefined
670
+ ? parseInt(transition.days, 10)
671
+ : undefined,
672
+ date: transition.date,
673
+ storageClass: transition.storageClass,
607
674
  }
608
675
  : undefined,
609
- }));
676
+ };
677
+ });
610
678
  }
611
679
  }
612
680
  catch {
613
681
  // Lifecycle config might not exist
614
682
  }
683
+ // Get versioning status (GetBucketVersioning)
684
+ let versioningConfig;
685
+ try {
686
+ const versioningResult = await ossClient.getBucketVersioning(bucketName);
687
+ if (versioningResult?.versionStatus === 'Enabled' ||
688
+ versioningResult?.versionStatus === 'Suspended') {
689
+ versioningConfig = { status: versioningResult.versionStatus };
690
+ }
691
+ }
692
+ catch {
693
+ // Versioning config might not exist
694
+ }
695
+ // Get server-side encryption (GetBucketEncryption)
696
+ let encryptionConfig;
697
+ try {
698
+ const encryptionResult = await ossClient.getBucketEncryption(bucketName);
699
+ const enc = encryptionResult?.encryption;
700
+ if (enc?.SSEAlgorithm) {
701
+ encryptionConfig = {
702
+ sseAlgorithm: enc.SSEAlgorithm,
703
+ kmsMasterKeyId: enc.KMSMasterKeyID,
704
+ kmsDataEncryption: enc.KMSDataEncryption,
705
+ };
706
+ }
707
+ }
708
+ catch {
709
+ // Encryption config might not exist
710
+ }
711
+ // Get transfer acceleration status (GetBucketTransferAcceleration)
712
+ let transferAccelerationStatus;
713
+ try {
714
+ const enabled = await operations.getTransferAccelerationStatus(bucketName);
715
+ transferAccelerationStatus = enabled ? 'Enabled' : 'Disabled';
716
+ }
717
+ catch {
718
+ // Transfer acceleration might not be configured
719
+ }
720
+ // Get replication rules (GetBucketReplication)
721
+ let replicationRules;
722
+ try {
723
+ const replicationResponse = await ossRequest(ossClient, {
724
+ method: 'GET',
725
+ bucket: bucketName,
726
+ subres: { replication: '' },
727
+ successStatuses: [200],
728
+ });
729
+ const replicationXml = replicationResponse.data || '';
730
+ const parsedRules = parseReplicationRules(replicationXml);
731
+ if (parsedRules.length > 0) {
732
+ replicationRules = parsedRules;
733
+ }
734
+ }
735
+ catch {
736
+ // Replication config might not exist
737
+ }
738
+ // Get bucket policy (GetBucketPolicy)
739
+ let policy;
740
+ try {
741
+ const policyResult = await operations.getBucketPolicy(bucketName);
742
+ if (policyResult) {
743
+ policy = JSON.stringify(policyResult);
744
+ }
745
+ }
746
+ catch {
747
+ // No bucket policy configured
748
+ }
749
+ // Get bucket tags
750
+ let tags;
751
+ try {
752
+ const tagsResult = await ossClient.getBucketTags(bucketName);
753
+ if (tagsResult.tag) {
754
+ tags = Object.entries(tagsResult.tag).map(([key, value]) => ({ key, value }));
755
+ }
756
+ }
757
+ catch {
758
+ // No bucket tags configured
759
+ }
615
760
  // Build owner info
616
761
  const owner = bucket?.Owner
617
762
  ? {
@@ -635,6 +780,12 @@ const parseXmlResponse = (xml, tagName) => {
635
780
  loggingConfig,
636
781
  corsRules,
637
782
  lifecycleRules,
783
+ versioningConfig,
784
+ encryptionConfig,
785
+ transferAccelerationStatus,
786
+ replicationRules,
787
+ tags,
788
+ policy,
638
789
  };
639
790
  }
640
791
  catch (error) {
@@ -814,5 +965,6 @@ const parseXmlResponse = (xml, tagName) => {
814
965
  }
815
966
  },
816
967
  };
968
+ return operations;
817
969
  };
818
970
  exports.createOssOperations = createOssOperations;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createRdsOperations = exports.RdsInstanceStatus = void 0;
4
4
  const logger_1 = require("../logger");
5
5
  const lang_1 = require("../../lang");
6
+ const polling_1 = require("../polling");
6
7
  var RdsInstanceStatus;
7
8
  (function (RdsInstanceStatus) {
8
9
  RdsInstanceStatus["RUNNING"] = "Running";
@@ -12,29 +13,40 @@ var RdsInstanceStatus;
12
13
  RdsInstanceStatus["RESTARTING"] = "Restarting";
13
14
  })(RdsInstanceStatus || (exports.RdsInstanceStatus = RdsInstanceStatus = {}));
14
15
  const waitForRdsInstanceReady = async (getInstance, instanceId) => {
15
- const maxAttempts = 60;
16
- let attempts = 0;
17
- while (attempts < maxAttempts) {
18
- const instance = await getInstance(instanceId);
19
- if (!instance) {
20
- throw new Error(lang_1.lang.__('RDS_INSTANCE_NOT_FOUND', { instanceId }));
21
- }
22
- if (instance.dbInstanceStatus === RdsInstanceStatus.RUNNING) {
23
- logger_1.logger.info(lang_1.lang.__('RDS_INSTANCE_READY', { instanceId }));
24
- return;
25
- }
26
- if (instance.dbInstanceStatus === RdsInstanceStatus.DELETED ||
27
- instance.dbInstanceStatus === RdsInstanceStatus.DELETE_FAILED) {
28
- throw new Error(lang_1.lang.__('RDS_INSTANCE_ERROR_STATE', { status: instance.dbInstanceStatus }));
16
+ try {
17
+ await (0, polling_1.pollUntil)({
18
+ description: `RDS instance ${instanceId} to be ready`,
19
+ fetch: async () => {
20
+ const instance = await getInstance(instanceId);
21
+ if (!instance) {
22
+ throw new Error(lang_1.lang.__('RDS_INSTANCE_NOT_FOUND', { instanceId }));
23
+ }
24
+ if (instance.dbInstanceStatus === RdsInstanceStatus.DELETED ||
25
+ instance.dbInstanceStatus === RdsInstanceStatus.DELETE_FAILED) {
26
+ throw new Error(lang_1.lang.__('RDS_INSTANCE_ERROR_STATE', { status: instance.dbInstanceStatus }));
27
+ }
28
+ return instance;
29
+ },
30
+ isDone: (instance) => instance?.dbInstanceStatus === RdsInstanceStatus.RUNNING,
31
+ intervalMs: 10000,
32
+ maxAttempts: 60,
33
+ onProgress: (instance) => {
34
+ if (instance) {
35
+ logger_1.logger.info(lang_1.lang.__('RDS_INSTANCE_WAITING', {
36
+ instanceId,
37
+ status: instance.dbInstanceStatus ?? 'unknown',
38
+ }));
39
+ }
40
+ },
41
+ });
42
+ logger_1.logger.info(lang_1.lang.__('RDS_INSTANCE_READY', { instanceId }));
43
+ }
44
+ catch (e) {
45
+ if (e instanceof polling_1.PollingTimeoutError) {
46
+ throw new Error(lang_1.lang.__('RDS_INSTANCE_TIMEOUT_READY', { instanceId }), { cause: e });
29
47
  }
30
- logger_1.logger.info(lang_1.lang.__('RDS_INSTANCE_WAITING', {
31
- instanceId,
32
- status: instance.dbInstanceStatus ?? 'unknown',
33
- }));
34
- await new Promise((resolve) => setTimeout(resolve, 10000));
35
- attempts++;
48
+ throw e;
36
49
  }
37
- throw new Error(lang_1.lang.__('RDS_INSTANCE_TIMEOUT_READY', { instanceId }));
38
50
  };
39
51
  const createRdsOperations = (rdsClient, context) => {
40
52
  const operations = {
@@ -65,6 +77,8 @@ const createRdsOperations = (rdsClient, context) => {
65
77
  }
66
78
  : undefined,
67
79
  BurstingEnabled: config.burstingEnabled,
80
+ // SDK serializes Tag as Tag.1.Key / Tag.1.Value (ownership tag for idempotent adoption)
81
+ Tag: config.tags,
68
82
  };
69
83
  try {
70
84
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -95,7 +109,7 @@ const createRdsOperations = (rdsClient, context) => {
95
109
  return null;
96
110
  }
97
111
  const instance = response.body.Items.DBInstanceAttribute[0];
98
- return {
112
+ const info = {
99
113
  dbInstanceId: instance.DBInstanceId,
100
114
  dbInstanceDescription: instance.DBInstanceDescription,
101
115
  engine: instance.Engine,
@@ -104,12 +118,14 @@ const createRdsOperations = (rdsClient, context) => {
104
118
  dbInstanceStorage: instance.DBInstanceStorage,
105
119
  category: instance.Category,
106
120
  dbInstanceStorageType: instance.DBInstanceStorageType,
107
- serverlessConfig: instance.ServerlessConfig
121
+ serverlessConfig: instance.serverlessConfig
108
122
  ? {
109
- minCapacity: instance.ServerlessConfig.MinCapacity,
110
- maxCapacity: instance.ServerlessConfig.MaxCapacity,
111
- autoPause: instance.ServerlessConfig.AutoPause,
112
- switchForce: instance.ServerlessConfig.SwitchForce,
123
+ // DescribeDBInstanceAttribute returns scaleMin/scaleMax (not
124
+ // MinCapacity/MaxCapacity) — map the actual cloud field names.
125
+ minCapacity: instance.serverlessConfig.scaleMin,
126
+ maxCapacity: instance.serverlessConfig.scaleMax,
127
+ autoPause: instance.serverlessConfig.autoPause,
128
+ switchForce: instance.serverlessConfig.switchForce,
113
129
  }
114
130
  : undefined,
115
131
  masterUsername: instance.MasterUsername,
@@ -119,11 +135,95 @@ const createRdsOperations = (rdsClient, context) => {
119
135
  connectionString: instance.ConnectionString,
120
136
  port: instance.Port,
121
137
  dbInstanceStatus: instance.DBInstanceStatus,
122
- createTime: instance.CreateTime,
138
+ createTime: instance.CreateTime ?? instance.CreationTime,
123
139
  regionId: instance.RegionId,
124
140
  securityIPList: instance.SecurityIPList,
125
141
  multiAZ: instance.MultiAZ === 'true',
142
+ // Maximum-detail fields — retain everything DescribeDBInstanceAttribute
143
+ // returns so state keeps the full cloud resource detail.
144
+ dbInstanceCpu: instance.DBInstanceCPU,
145
+ dbInstanceMemory: instance.DBInstanceMemory,
146
+ payType: instance.PayType,
147
+ expireTime: instance.ExpireTime,
148
+ maintainTime: instance.MaintainTime,
149
+ maxConnections: instance.MaxConnections,
150
+ maxIOPS: instance.MaxIOPS,
151
+ resourceGroupId: instance.ResourceGroupId,
152
+ deletionProtection: instance.DeletionProtection,
153
+ lockMode: instance.LockMode,
154
+ lockReason: instance.LockReason,
155
+ connectionMode: instance.ConnectionMode,
156
+ dbInstanceDiskUsed: instance.DBInstanceDiskUsed,
157
+ dbInstanceType: instance.DBInstanceType,
158
+ instanceNetworkType: instance.InstanceNetworkType,
159
+ timeZone: instance.TimeZone,
160
+ currentKernelVersion: instance.CurrentKernelVersion,
161
+ latestKernelVersion: instance.LatestKernelVersion,
162
+ masterZone: instance.MasterZone,
163
+ masterInstanceId: instance.MasterInstanceId,
164
+ slaveZones: instance.SlaveZones?.slaveZone?.map((z) => ({ zoneId: z.zoneId })),
165
+ readOnlyDBInstanceIds: instance.ReadOnlyDBInstanceIds?.readOnlyDBInstanceId
166
+ ?.map((r) => r.DBInstanceId)
167
+ .filter((id) => !!id),
168
+ burstingEnabled: instance.BurstingEnabled,
169
+ computeBurstEnabled: instance.ComputeBurstEnabled,
126
170
  };
171
+ try {
172
+ const tags = await operations.getInstanceTags(instanceId);
173
+ if (tags.length > 0) {
174
+ info.tags = tags;
175
+ }
176
+ }
177
+ catch {
178
+ // Tags are best-effort; instance detail is still returned without them.
179
+ }
180
+ return info;
181
+ }
182
+ catch (error) {
183
+ logger_1.logger.error(lang_1.lang.__('RDS_INSTANCE_GET_FAILED', { error: String(error) }));
184
+ return null;
185
+ }
186
+ },
187
+ getInstanceTags: async (instanceId) => {
188
+ const params = {
189
+ RegionId: context.region,
190
+ ResourceType: 'INSTANCE',
191
+ ResourceId: [instanceId],
192
+ };
193
+ try {
194
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
195
+ const response = await rdsClient.listTagResources(params);
196
+ return (response.body?.tagResources?.tagResource ?? []).map((t) => ({
197
+ key: t.tagKey,
198
+ value: t.tagValue,
199
+ }));
200
+ }
201
+ catch (error) {
202
+ logger_1.logger.error(lang_1.lang.__('RDS_INSTANCE_GET_FAILED', { error: String(error) }));
203
+ return [];
204
+ }
205
+ },
206
+ getInstanceByName: async (name) => {
207
+ const params = {
208
+ RegionId: context.region,
209
+ SearchKey: name,
210
+ PageSize: 100,
211
+ };
212
+ try {
213
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
214
+ const response = await rdsClient.describeDBInstances(params);
215
+ // SearchKey fuzzy-matches DBInstanceId OR DBInstanceDescription, so filter
216
+ // to an exact description match to avoid adopting an unrelated instance.
217
+ const match = (response.body?.items?.DBInstance ?? []).find((i) => i.DBInstanceDescription === name);
218
+ if (!match?.DBInstanceId) {
219
+ return null;
220
+ }
221
+ const instance = await operations.getInstance(match.DBInstanceId);
222
+ if (!instance) {
223
+ return null;
224
+ }
225
+ const tags = await operations.getInstanceTags(match.DBInstanceId);
226
+ return { ...instance, tags };
127
227
  }
128
228
  catch (error) {
129
229
  logger_1.logger.error(lang_1.lang.__('RDS_INSTANCE_GET_FAILED', { error: String(error) }));
@@ -173,19 +273,23 @@ const createRdsOperations = (rdsClient, context) => {
173
273
  await rdsClient.deleteDBInstance(params);
174
274
  logger_1.logger.info(lang_1.lang.__('RDS_INSTANCE_DELETION_INITIATED', { instanceId }));
175
275
  // Wait for instance to be deleted
176
- const maxAttempts = 60;
177
- let attempts = 0;
178
- while (attempts < maxAttempts) {
179
- const instance = await operations.getInstance(instanceId);
180
- if (!instance) {
181
- logger_1.logger.info(lang_1.lang.__('RDS_INSTANCE_DELETED', { instanceId }));
182
- return;
276
+ try {
277
+ await (0, polling_1.pollUntil)({
278
+ description: `RDS instance ${instanceId} to be deleted`,
279
+ fetch: () => operations.getInstance(instanceId),
280
+ isDone: (instance) => instance === null,
281
+ intervalMs: 10000,
282
+ maxAttempts: 60,
283
+ onProgress: () => logger_1.logger.info(lang_1.lang.__('RDS_INSTANCE_WAITING_DELETE', { instanceId })),
284
+ });
285
+ }
286
+ catch (e) {
287
+ if (e instanceof polling_1.PollingTimeoutError) {
288
+ throw new Error(lang_1.lang.__('RDS_INSTANCE_TIMEOUT_DELETE', { instanceId }), { cause: e });
183
289
  }
184
- logger_1.logger.info(lang_1.lang.__('RDS_INSTANCE_WAITING_DELETE', { instanceId }));
185
- await new Promise((resolve) => setTimeout(resolve, 10000));
186
- attempts++;
290
+ throw e;
187
291
  }
188
- throw new Error(lang_1.lang.__('RDS_INSTANCE_TIMEOUT_DELETE', { instanceId }));
292
+ logger_1.logger.info(lang_1.lang.__('RDS_INSTANCE_DELETED', { instanceId }));
189
293
  }
190
294
  catch (error) {
191
295
  // If instance is not found, consider it deleted
@@ -35,39 +35,69 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.createSlsOperations = void 0;
37
37
  const sls = __importStar(require("@alicloud/sls20201230"));
38
+ const logger_1 = require("../logger");
39
+ const polling_1 = require("../polling");
38
40
  const waitForSlsProject = async (getProject, projectName) => {
39
- let retries = 0;
40
- while (retries < 30) {
41
- try {
42
- const project = await getProject(projectName);
43
- if (project && project.status === 'Normal') {
44
- return project;
45
- }
46
- }
47
- catch {
48
- // Project not ready yet
41
+ try {
42
+ const project = await (0, polling_1.pollUntil)({
43
+ description: `SLS project ${projectName} to be ready`,
44
+ fetch: async () => {
45
+ try {
46
+ return await getProject(projectName);
47
+ }
48
+ catch {
49
+ // Project not ready yet
50
+ return null;
51
+ }
52
+ },
53
+ isDone: (project) => project?.status === 'Normal',
54
+ intervalMs: 3000,
55
+ maxAttempts: 30,
56
+ onProgress: (project) => {
57
+ if (project) {
58
+ logger_1.logger.info(`Waiting for SLS project ${projectName} to be ready (current status: ${project.status ?? 'unknown'})`);
59
+ }
60
+ },
61
+ });
62
+ return project;
63
+ }
64
+ catch (e) {
65
+ if (e instanceof polling_1.PollingTimeoutError) {
66
+ return { projectName };
49
67
  }
50
- await new Promise((resolve) => setTimeout(resolve, 3000));
51
- retries++;
68
+ throw e;
52
69
  }
53
- return { projectName };
54
70
  };
55
71
  const waitForSlsLogstore = async (getLogstore, projectName, logstoreName, ttl) => {
56
- let retries = 0;
57
- while (retries < 30) {
58
- try {
59
- const logstore = await getLogstore(projectName, logstoreName);
60
- if (logstore) {
61
- return logstore;
62
- }
63
- }
64
- catch {
65
- // Logstore not ready yet
72
+ try {
73
+ const logstore = await (0, polling_1.pollUntil)({
74
+ description: `SLS logstore ${projectName}/${logstoreName} to be ready`,
75
+ fetch: async () => {
76
+ try {
77
+ return await getLogstore(projectName, logstoreName);
78
+ }
79
+ catch {
80
+ // Logstore not ready yet
81
+ return null;
82
+ }
83
+ },
84
+ isDone: (logstore) => logstore != null,
85
+ intervalMs: 3000,
86
+ maxAttempts: 30,
87
+ onProgress: (logstore) => {
88
+ if (logstore) {
89
+ logger_1.logger.info(`Waiting for SLS logstore ${projectName}/${logstoreName} to be ready...`);
90
+ }
91
+ },
92
+ });
93
+ return logstore;
94
+ }
95
+ catch (e) {
96
+ if (e instanceof polling_1.PollingTimeoutError) {
97
+ return { logstoreName, projectName, ttl };
66
98
  }
67
- await new Promise((resolve) => setTimeout(resolve, 3000));
68
- retries++;
99
+ throw e;
69
100
  }
70
- return { logstoreName, projectName, ttl };
71
101
  };
72
102
  const createSlsOperations = (slsClient) => {
73
103
  const operations = {
@@ -108,7 +138,18 @@ const createSlsOperations = (slsClient) => {
108
138
  const request = new sls.DeleteProjectRequest({});
109
139
  await slsClient.deleteProject(projectName, request);
110
140
  },
111
- createLogstore: async (projectName, logstoreName, ttl = 7) => {
141
+ getProjectTags: async (projectName) => {
142
+ const request = new sls.ListTagResourcesRequest({
143
+ resourceId: [projectName],
144
+ resourceType: 'project',
145
+ });
146
+ const response = await slsClient.listTagResources(request);
147
+ return (response.body?.tagResources ?? []).map((tagResource) => ({
148
+ key: tagResource.tagKey ?? '',
149
+ value: tagResource.tagValue ?? '',
150
+ }));
151
+ },
152
+ createLogstore: async (projectName, logstoreName, ttl = 30) => {
112
153
  const request = new sls.CreateLogStoreRequest({
113
154
  logstoreName,
114
155
  ttl,
@@ -146,6 +187,11 @@ const createSlsOperations = (slsClient) => {
146
187
  deleteLogstore: async (projectName, logstoreName) => {
147
188
  await slsClient.deleteLogStore(projectName, logstoreName);
148
189
  },
190
+ listLogStores: async (projectName) => {
191
+ const request = new sls.ListLogStoresRequest({ size: 500 });
192
+ const response = await slsClient.listLogStores(projectName, request);
193
+ return response.body?.logstores ?? [];
194
+ },
149
195
  createIndex: async (projectName, logstoreName) => {
150
196
  const request = new sls.CreateIndexRequest({
151
197
  body: new sls.Index({
@@ -209,9 +255,25 @@ const createSlsOperations = (slsClient) => {
209
255
  waitForProject: async (projectName) => {
210
256
  return waitForSlsProject(operations.getProject, projectName);
211
257
  },
212
- waitForLogstore: async (projectName, logstoreName, ttl = 7) => {
258
+ waitForLogstore: async (projectName, logstoreName, ttl = 30) => {
213
259
  return waitForSlsLogstore(operations.getLogstore, projectName, logstoreName, ttl);
214
260
  },
261
+ addTags: async (config) => {
262
+ const request = new sls.TagResourcesRequest({
263
+ resourceId: [config.resourceId],
264
+ resourceType: config.resourceType,
265
+ tags: config.tags,
266
+ });
267
+ await slsClient.tagResources(request);
268
+ },
269
+ removeTags: async (config) => {
270
+ const request = new sls.UntagResourcesRequest({
271
+ resourceId: [config.resourceId],
272
+ resourceType: config.resourceType,
273
+ tags: config.tagKeys,
274
+ });
275
+ await slsClient.untagResources(request);
276
+ },
215
277
  };
216
278
  return operations;
217
279
  };