@geek-fun/serverlessinsight 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/.gitattributes +1 -0
  2. package/README.md +108 -8
  3. package/README.zh-CN.md +52 -8
  4. package/dist/package.json +37 -35
  5. package/dist/src/commands/deploy.js +17 -7
  6. package/dist/src/commands/destroy.js +27 -4
  7. package/dist/src/commands/forceUnlock.js +61 -0
  8. package/dist/src/commands/index.js +86 -14
  9. package/dist/src/commands/local.js +10 -1
  10. package/dist/src/commands/plan.js +33 -0
  11. package/dist/src/commands/template.js +3 -1
  12. package/dist/src/commands/validate.js +2 -1
  13. package/dist/src/common/aliyunClient/apigwOperations.js +652 -0
  14. package/dist/src/common/aliyunClient/dnsOperations.js +90 -0
  15. package/dist/src/common/aliyunClient/ecsOperations.js +141 -0
  16. package/dist/src/common/aliyunClient/esOperations.js +219 -0
  17. package/dist/src/common/aliyunClient/fc3Operations.js +270 -0
  18. package/dist/src/common/aliyunClient/index.js +141 -0
  19. package/dist/src/common/aliyunClient/nasOperations.js +233 -0
  20. package/dist/src/common/aliyunClient/ossOperations.js +237 -0
  21. package/dist/src/common/aliyunClient/ramOperations.js +205 -0
  22. package/dist/src/common/aliyunClient/rdsOperations.js +206 -0
  23. package/dist/src/common/aliyunClient/slsOperations.js +218 -0
  24. package/dist/src/common/aliyunClient/tablestoreOperations.js +199 -0
  25. package/dist/src/common/aliyunClient/types.js +2 -0
  26. package/dist/src/common/constants.js +7 -1
  27. package/dist/src/common/context.js +32 -14
  28. package/dist/src/common/credentials.js +39 -0
  29. package/dist/src/common/dependencyGraph/graph.js +280 -0
  30. package/dist/src/common/dependencyGraph/index.js +18 -0
  31. package/dist/src/common/dependencyGraph/types.js +2 -0
  32. package/dist/src/common/fileUtils.js +16 -0
  33. package/dist/src/common/hashUtils.js +121 -0
  34. package/dist/src/common/iacHelper.js +25 -97
  35. package/dist/src/common/imsClient.js +4 -0
  36. package/dist/src/common/index.js +7 -2
  37. package/dist/src/common/lockManager.js +212 -0
  38. package/dist/src/common/logger.js +89 -6
  39. package/dist/src/common/providerEnum.js +2 -3
  40. package/dist/src/common/runtimeMapper.js +160 -0
  41. package/dist/src/common/scfClient.js +84 -0
  42. package/dist/src/common/stateManager.js +107 -0
  43. package/dist/src/common/tencentClient/cosOperations.js +287 -0
  44. package/dist/src/common/tencentClient/esOperations.js +156 -0
  45. package/dist/src/common/tencentClient/index.js +116 -0
  46. package/dist/src/common/tencentClient/scfOperations.js +141 -0
  47. package/dist/src/common/tencentClient/tdsqlcOperations.js +211 -0
  48. package/dist/src/common/tencentClient/types.js +17 -0
  49. package/dist/src/lang/en.js +254 -0
  50. package/dist/src/lang/index.js +28 -8
  51. package/dist/src/lang/zh-CN.js +229 -0
  52. package/dist/src/parser/bucketParser.js +25 -12
  53. package/dist/src/parser/databaseParser.js +14 -10
  54. package/dist/src/parser/functionParser.js +19 -6
  55. package/dist/src/parser/parseUtils.js +74 -0
  56. package/dist/src/parser/tableParser.js +19 -17
  57. package/dist/src/stack/aliyunStack/apigwExecutor.js +84 -0
  58. package/dist/src/stack/aliyunStack/apigwPlanner.js +118 -0
  59. package/dist/src/stack/aliyunStack/apigwResource.js +339 -0
  60. package/dist/src/stack/aliyunStack/apigwTypes.js +125 -0
  61. package/dist/src/stack/aliyunStack/databaseExecutor.js +112 -0
  62. package/dist/src/stack/aliyunStack/databasePlanner.js +128 -0
  63. package/dist/src/stack/aliyunStack/databaseResource.js +228 -0
  64. package/dist/src/stack/aliyunStack/deployer.js +133 -0
  65. package/dist/src/stack/aliyunStack/destroyer.js +114 -0
  66. package/dist/src/stack/aliyunStack/esServerlessTypes.js +141 -0
  67. package/dist/src/stack/aliyunStack/fc3Executor.js +91 -0
  68. package/dist/src/stack/aliyunStack/fc3Planner.js +77 -0
  69. package/dist/src/stack/aliyunStack/fc3Resource.js +511 -0
  70. package/dist/src/stack/aliyunStack/fc3Types.js +76 -0
  71. package/dist/src/stack/aliyunStack/index.js +40 -0
  72. package/dist/src/stack/aliyunStack/ossExecutor.js +91 -0
  73. package/dist/src/stack/aliyunStack/ossPlanner.js +76 -0
  74. package/dist/src/stack/aliyunStack/ossResource.js +196 -0
  75. package/dist/src/stack/aliyunStack/ossTypes.js +50 -0
  76. package/dist/src/stack/aliyunStack/planner.js +37 -0
  77. package/dist/src/stack/aliyunStack/rdsTypes.js +217 -0
  78. package/dist/src/stack/aliyunStack/tablestoreExecutor.js +92 -0
  79. package/dist/src/stack/aliyunStack/tablestorePlanner.js +94 -0
  80. package/dist/src/stack/aliyunStack/tablestoreResource.js +120 -0
  81. package/dist/src/stack/aliyunStack/tablestoreTypes.js +77 -0
  82. package/dist/src/stack/bucketTypes.js +17 -0
  83. package/dist/src/stack/deploy.js +24 -77
  84. package/dist/src/stack/localStack/bucket.js +11 -6
  85. package/dist/src/stack/localStack/event.js +10 -5
  86. package/dist/src/stack/localStack/function.js +13 -7
  87. package/dist/src/stack/localStack/functionRunner.js +1 -1
  88. package/dist/src/stack/localStack/localServer.js +7 -6
  89. package/dist/src/stack/scfStack/cosExecutor.js +91 -0
  90. package/dist/src/stack/scfStack/cosPlanner.js +76 -0
  91. package/dist/src/stack/scfStack/cosResource.js +126 -0
  92. package/dist/src/stack/scfStack/cosTypes.js +46 -0
  93. package/dist/src/stack/scfStack/deployer.js +91 -0
  94. package/dist/src/stack/scfStack/destroyer.js +88 -0
  95. package/dist/src/stack/scfStack/esServerlessExecutor.js +105 -0
  96. package/dist/src/stack/scfStack/esServerlessPlanner.js +86 -0
  97. package/dist/src/stack/scfStack/esServerlessResource.js +94 -0
  98. package/dist/src/stack/scfStack/esServerlessTypes.js +48 -0
  99. package/dist/src/stack/scfStack/index.js +35 -0
  100. package/dist/src/stack/scfStack/planner.js +91 -0
  101. package/dist/src/stack/scfStack/scfExecutor.js +91 -0
  102. package/dist/src/stack/scfStack/scfPlanner.js +78 -0
  103. package/dist/src/stack/scfStack/scfResource.js +216 -0
  104. package/dist/src/stack/scfStack/scfTypes.js +41 -0
  105. package/dist/src/stack/scfStack/tdsqlcExecutor.js +105 -0
  106. package/dist/src/stack/scfStack/tdsqlcPlanner.js +90 -0
  107. package/dist/src/stack/scfStack/tdsqlcResource.js +146 -0
  108. package/dist/src/stack/scfStack/tdsqlcTypes.js +59 -0
  109. package/dist/src/types/domains/lock.js +2 -0
  110. package/dist/src/types/domains/resolvable.js +2 -0
  111. package/dist/src/types/domains/state.js +19 -0
  112. package/dist/src/types/index.js +4 -0
  113. package/dist/src/validator/bucketSchema.js +4 -10
  114. package/dist/src/validator/databaseSchema.js +36 -36
  115. package/dist/src/validator/eventSchema.js +3 -2
  116. package/dist/src/validator/functionSchema.js +51 -46
  117. package/dist/src/validator/iacSchema.js +52 -3
  118. package/dist/src/validator/rootSchema.js +47 -1
  119. package/dist/src/validator/tableschema.js +9 -8
  120. package/dist/src/validator/templateRefSchema.js +23 -0
  121. package/dist/tsconfig.tsbuildinfo +1 -1
  122. package/package.json +37 -35
  123. package/samples/README_TENCENT_COS.md +486 -0
  124. package/samples/README_TENCENT_SCF.md +272 -0
  125. package/samples/aliyun-poc-api.yml +1 -1
  126. package/samples/aliyun-poc-bucket.yml +0 -1
  127. package/samples/aliyun-poc-domain.yml +0 -1
  128. package/samples/aliyun-poc-es.yml +14 -13
  129. package/samples/aliyun-poc-rds.yml +0 -2
  130. package/samples/aliyun-poc-table.yml +1 -3
  131. package/samples/tencent-poc-cos.yml +20 -0
  132. package/samples/tencent-poc-scf.yml +36 -0
  133. package/dist/src/commands/index.d.ts +0 -2
  134. package/dist/src/common/index.d.ts +0 -11
  135. package/dist/src/common/rosAssets.js +0 -178
  136. package/dist/src/common/rosClient.js +0 -198
  137. package/dist/src/index.d.ts +0 -1
  138. package/dist/src/lang/index.d.ts +0 -3
  139. package/dist/src/parser/index.d.ts +0 -3
  140. package/dist/src/stack/index.d.ts +0 -1
  141. package/dist/src/stack/localStack/index.d.ts +0 -5
  142. package/dist/src/stack/rfsStack/index.d.ts +0 -9
  143. package/dist/src/stack/rosStack/bootstrap.js +0 -187
  144. package/dist/src/stack/rosStack/bucket.js +0 -127
  145. package/dist/src/stack/rosStack/database.js +0 -313
  146. package/dist/src/stack/rosStack/event.js +0 -143
  147. package/dist/src/stack/rosStack/function.js +0 -259
  148. package/dist/src/stack/rosStack/index.d.ts +0 -7
  149. package/dist/src/stack/rosStack/index.js +0 -75
  150. package/dist/src/stack/rosStack/stage.js +0 -46
  151. package/dist/src/stack/rosStack/table.js +0 -95
  152. package/dist/src/stack/rosStack/tag.js +0 -11
  153. package/dist/src/stack/rosStack/vars.js +0 -49
  154. package/dist/src/types/index.d.ts +0 -55
  155. package/dist/src/types/localStack/index.d.ts +0 -81
  156. package/dist/src/validator/index.d.ts +0 -1
  157. package/layers/si-bootstrap-sdk/Dockerfile-aliyuncli +0 -12
  158. package/layers/si-bootstrap-sdk/README.md +0 -1
  159. package/layers/si-bootstrap-sdk/package-lock.json +0 -875
  160. package/layers/si-bootstrap-sdk/package.json +0 -33
@@ -0,0 +1,287 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCosOperations = void 0;
4
+ const createCosOperations = (cosClient) => ({
5
+ createBucket: async (config) => {
6
+ // Create bucket
7
+ await new Promise((resolve, reject) => {
8
+ cosClient.putBucket({
9
+ Bucket: config.Bucket,
10
+ Region: config.Region,
11
+ }, (err) => {
12
+ if (err) {
13
+ reject(err);
14
+ }
15
+ else {
16
+ resolve();
17
+ }
18
+ });
19
+ });
20
+ // Set ACL if specified
21
+ if (config.ACL) {
22
+ await new Promise((resolve, reject) => {
23
+ cosClient.putBucketAcl({
24
+ Bucket: config.Bucket,
25
+ Region: config.Region,
26
+ ACL: config.ACL,
27
+ }, (err) => {
28
+ if (err) {
29
+ reject(err);
30
+ }
31
+ else {
32
+ resolve();
33
+ }
34
+ });
35
+ });
36
+ }
37
+ // Set website configuration if specified
38
+ if (config.WebsiteConfiguration) {
39
+ const websiteConfig = config.WebsiteConfiguration;
40
+ await new Promise((resolve, reject) => {
41
+ cosClient.putBucketWebsite({
42
+ Bucket: config.Bucket,
43
+ Region: config.Region,
44
+ WebsiteConfiguration: websiteConfig,
45
+ }, (err) => {
46
+ if (err) {
47
+ reject(err);
48
+ }
49
+ else {
50
+ resolve();
51
+ }
52
+ });
53
+ });
54
+ }
55
+ },
56
+ getBucket: async (bucketName, region) => {
57
+ try {
58
+ // Check if bucket exists
59
+ await new Promise((resolve, reject) => {
60
+ cosClient.headBucket({
61
+ Bucket: bucketName,
62
+ Region: region,
63
+ }, (err, data) => {
64
+ if (err) {
65
+ reject(err);
66
+ }
67
+ else {
68
+ resolve(data);
69
+ }
70
+ });
71
+ });
72
+ // Get ACL
73
+ let acl;
74
+ let accessControlPolicy;
75
+ try {
76
+ const aclResult = await new Promise((resolve, reject) => {
77
+ cosClient.getBucketAcl({
78
+ Bucket: bucketName,
79
+ Region: region,
80
+ }, (err, data) => {
81
+ if (err) {
82
+ reject(err);
83
+ }
84
+ else {
85
+ resolve(data);
86
+ }
87
+ });
88
+ });
89
+ acl = aclResult.ACL;
90
+ accessControlPolicy = {
91
+ owner: aclResult.Owner
92
+ ? {
93
+ id: aclResult.Owner.ID,
94
+ displayName: undefined,
95
+ }
96
+ : undefined,
97
+ grants: aclResult.Grants?.map((g) => ({
98
+ grantee: g.Grantee
99
+ ? {
100
+ type: 'ID' in g.Grantee ? 'CanonicalUser' : 'Group',
101
+ uri: 'URI' in g.Grantee ? g.Grantee.URI : undefined,
102
+ id: 'ID' in g.Grantee ? g.Grantee.ID : undefined,
103
+ displayName: undefined,
104
+ }
105
+ : undefined,
106
+ permission: g.Permission,
107
+ })),
108
+ };
109
+ }
110
+ catch {
111
+ // ACL might not be accessible due to insufficient permissions
112
+ }
113
+ // Get CORS configuration
114
+ let corsConfiguration;
115
+ try {
116
+ const corsResult = await new Promise((resolve, reject) => {
117
+ cosClient.getBucketCors({
118
+ Bucket: bucketName,
119
+ Region: region,
120
+ }, (err, data) => {
121
+ if (err) {
122
+ reject(err);
123
+ }
124
+ else {
125
+ resolve(data);
126
+ }
127
+ });
128
+ });
129
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
130
+ corsConfiguration = corsResult.CORSRules?.map((r) => ({
131
+ id: r.ID,
132
+ allowedOrigins: r.AllowedOrigin,
133
+ allowedMethods: r.AllowedMethod,
134
+ allowedHeaders: r.AllowedHeader,
135
+ exposeHeaders: r.ExposeHeader,
136
+ maxAgeSeconds: r.MaxAgeSeconds,
137
+ }));
138
+ }
139
+ catch {
140
+ // CORS might not be configured
141
+ }
142
+ // Get website configuration
143
+ let websiteConfig;
144
+ try {
145
+ const websiteResult = await new Promise((resolve, reject) => {
146
+ cosClient.getBucketWebsite({
147
+ Bucket: bucketName,
148
+ Region: region,
149
+ }, (err, data) => {
150
+ if (err) {
151
+ reject(err);
152
+ }
153
+ else {
154
+ resolve(data);
155
+ }
156
+ });
157
+ });
158
+ if (websiteResult.WebsiteConfiguration?.IndexDocument ||
159
+ websiteResult.WebsiteConfiguration?.ErrorDocument) {
160
+ websiteConfig = {
161
+ IndexDocument: websiteResult.WebsiteConfiguration.IndexDocument,
162
+ ErrorDocument: websiteResult.WebsiteConfiguration.ErrorDocument,
163
+ };
164
+ }
165
+ }
166
+ catch {
167
+ // Website configuration might not be set
168
+ }
169
+ // Get versioning configuration
170
+ let versioningConfig;
171
+ try {
172
+ const versioningResult = await new Promise((resolve, reject) => {
173
+ cosClient.getBucketVersioning({
174
+ Bucket: bucketName,
175
+ Region: region,
176
+ }, (err, data) => {
177
+ if (err) {
178
+ reject(err);
179
+ }
180
+ else {
181
+ resolve(data);
182
+ }
183
+ });
184
+ });
185
+ versioningConfig = {
186
+ status: versioningResult.VersioningConfiguration?.Status,
187
+ };
188
+ }
189
+ catch {
190
+ // Versioning might not be accessible
191
+ }
192
+ // Get tagging configuration
193
+ let taggingConfig;
194
+ try {
195
+ const taggingResult = await new Promise((resolve, reject) => {
196
+ cosClient.getBucketTagging({
197
+ Bucket: bucketName,
198
+ Region: region,
199
+ }, (err, data) => {
200
+ if (err) {
201
+ reject(err);
202
+ }
203
+ else {
204
+ resolve(data);
205
+ }
206
+ });
207
+ });
208
+ taggingConfig = {
209
+ tags: taggingResult.Tags?.map((t) => ({
210
+ key: t.Key,
211
+ value: t.Value,
212
+ })),
213
+ };
214
+ }
215
+ catch {
216
+ // Tagging might not be configured
217
+ }
218
+ return {
219
+ Name: bucketName,
220
+ Location: region,
221
+ ACL: acl,
222
+ WebsiteConfiguration: websiteConfig,
223
+ AccessControlPolicy: accessControlPolicy,
224
+ CorsConfiguration: corsConfiguration,
225
+ VersioningConfiguration: versioningConfig,
226
+ TaggingConfiguration: taggingConfig,
227
+ };
228
+ }
229
+ catch (error) {
230
+ if (error && typeof error === 'object' && 'statusCode' in error) {
231
+ const statusCode = error.statusCode;
232
+ if (statusCode === 404) {
233
+ return null;
234
+ }
235
+ }
236
+ throw error;
237
+ }
238
+ },
239
+ updateBucketAcl: async (bucketName, region, acl) => {
240
+ await new Promise((resolve, reject) => {
241
+ cosClient.putBucketAcl({
242
+ Bucket: bucketName,
243
+ Region: region,
244
+ ACL: acl,
245
+ }, (err) => {
246
+ if (err) {
247
+ reject(err);
248
+ }
249
+ else {
250
+ resolve();
251
+ }
252
+ });
253
+ });
254
+ },
255
+ updateBucketWebsite: async (bucketName, region, websiteConfig) => {
256
+ await new Promise((resolve, reject) => {
257
+ cosClient.putBucketWebsite({
258
+ Bucket: bucketName,
259
+ Region: region,
260
+ WebsiteConfiguration: websiteConfig,
261
+ }, (err) => {
262
+ if (err) {
263
+ reject(err);
264
+ }
265
+ else {
266
+ resolve();
267
+ }
268
+ });
269
+ });
270
+ },
271
+ deleteBucket: async (bucketName, region) => {
272
+ await new Promise((resolve, reject) => {
273
+ cosClient.deleteBucket({
274
+ Bucket: bucketName,
275
+ Region: region,
276
+ }, (err) => {
277
+ if (err) {
278
+ reject(err);
279
+ }
280
+ else {
281
+ resolve();
282
+ }
283
+ });
284
+ });
285
+ },
286
+ });
287
+ exports.createCosOperations = createCosOperations;
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTencentEsOperations = void 0;
4
+ const types_1 = require("./types");
5
+ const logger_1 = require("../logger");
6
+ const lang_1 = require("../../lang");
7
+ const waitForSpaceReady = async (getSpace, spaceId) => {
8
+ const maxAttempts = 60;
9
+ let attempts = 0;
10
+ while (attempts < maxAttempts) {
11
+ const space = await getSpace(spaceId);
12
+ if (!space) {
13
+ throw new Error(lang_1.lang.__('TENCENT_ES_SPACE_NOT_FOUND', { spaceId }));
14
+ }
15
+ if (space.Status === types_1.TencentEsSpaceStatus.NORMAL) {
16
+ logger_1.logger.info(lang_1.lang.__('TENCENT_ES_SPACE_READY', { spaceId }));
17
+ return;
18
+ }
19
+ if (space.Status === types_1.TencentEsSpaceStatus.DELETED ||
20
+ space.Status === types_1.TencentEsSpaceStatus.DELETING) {
21
+ throw new Error(lang_1.lang.__('TENCENT_ES_SPACE_ERROR_STATE', { status: String(space.Status) }));
22
+ }
23
+ logger_1.logger.info(lang_1.lang.__('TENCENT_ES_SPACE_WAITING', { spaceId, status: String(space.Status) }));
24
+ await new Promise((resolve) => setTimeout(resolve, 10000));
25
+ attempts++;
26
+ }
27
+ throw new Error(lang_1.lang.__('TENCENT_ES_SPACE_TIMEOUT_READY', { spaceId }));
28
+ };
29
+ const waitForSpaceDeleted = async (getSpace, spaceId) => {
30
+ const maxAttempts = 60;
31
+ let attempts = 0;
32
+ while (attempts < maxAttempts) {
33
+ const space = await getSpace(spaceId);
34
+ if (!space) {
35
+ logger_1.logger.info(lang_1.lang.__('TENCENT_ES_SPACE_DELETED', { spaceId }));
36
+ return;
37
+ }
38
+ if (space.Status === types_1.TencentEsSpaceStatus.DELETED) {
39
+ logger_1.logger.info(lang_1.lang.__('TENCENT_ES_SPACE_DELETED', { spaceId }));
40
+ return;
41
+ }
42
+ logger_1.logger.info(lang_1.lang.__('TENCENT_ES_SPACE_WAITING_DELETE', { spaceId }));
43
+ await new Promise((resolve) => setTimeout(resolve, 10000));
44
+ attempts++;
45
+ }
46
+ throw new Error(lang_1.lang.__('TENCENT_ES_SPACE_TIMEOUT_DELETE', { spaceId }));
47
+ };
48
+ const createTencentEsOperations = (esClient, _context) => {
49
+ const operations = {
50
+ createSpace: async (config) => {
51
+ const params = {
52
+ SpaceName: config.SpaceName,
53
+ };
54
+ if (config.VpcInfo && config.VpcInfo.length > 0) {
55
+ params.VpcInfo = config.VpcInfo;
56
+ }
57
+ if (config.Zone) {
58
+ params.Zone = config.Zone;
59
+ }
60
+ if (config.KibanaWhiteIpList && config.KibanaWhiteIpList.length > 0) {
61
+ params.KibanaWhiteIpList = config.KibanaWhiteIpList;
62
+ }
63
+ try {
64
+ const response = await esClient.CreateServerlessSpaceV2(params);
65
+ logger_1.logger.info(lang_1.lang.__('TENCENT_ES_SPACE_CREATION_INITIATED'));
66
+ if (!response.SpaceId) {
67
+ throw new Error(lang_1.lang.__('TENCENT_ES_SPACE_NO_ID_RETURNED'));
68
+ }
69
+ const spaceId = response.SpaceId;
70
+ await waitForSpaceReady(operations.getSpace, spaceId);
71
+ return spaceId;
72
+ }
73
+ catch (error) {
74
+ logger_1.logger.error(lang_1.lang.__('TENCENT_ES_SPACE_CREATION_FAILED', { error: String(error) }));
75
+ throw error;
76
+ }
77
+ },
78
+ getSpace: async (spaceId) => {
79
+ const params = {
80
+ SpaceIds: [spaceId],
81
+ };
82
+ try {
83
+ const response = await esClient.DescribeServerlessSpaces(params);
84
+ if (!response.ServerlessSpaces || response.ServerlessSpaces.length === 0) {
85
+ return null;
86
+ }
87
+ const space = response.ServerlessSpaces[0];
88
+ return {
89
+ SpaceId: space.SpaceId || '',
90
+ SpaceName: space.SpaceName || '',
91
+ Status: space.Status ?? types_1.TencentEsSpaceStatus.CREATING,
92
+ CreateTime: space.CreateTime,
93
+ IndexCount: space.IndexCount,
94
+ KibanaUrl: space.KibanaUrl,
95
+ KibanaPrivateUrl: space.KibanaPrivateUrl,
96
+ };
97
+ }
98
+ catch (error) {
99
+ logger_1.logger.error(lang_1.lang.__('TENCENT_ES_SPACE_GET_FAILED', { error: String(error) }));
100
+ return null;
101
+ }
102
+ },
103
+ updateSpace: async (spaceId, config) => {
104
+ const params = {
105
+ SpaceId: spaceId,
106
+ SpaceName: config.SpaceName,
107
+ };
108
+ if (config.KibanaWhiteIpList && config.KibanaWhiteIpList.length > 0) {
109
+ params.KibanaWhiteIpList = config.KibanaWhiteIpList;
110
+ }
111
+ try {
112
+ await esClient.UpdateServerlessSpace(params);
113
+ logger_1.logger.info(lang_1.lang.__('TENCENT_ES_SPACE_UPDATED', { spaceId }));
114
+ await waitForSpaceReady(operations.getSpace, spaceId);
115
+ }
116
+ catch (error) {
117
+ logger_1.logger.error(lang_1.lang.__('TENCENT_ES_SPACE_UPDATE_FAILED', { error: String(error) }));
118
+ throw error;
119
+ }
120
+ },
121
+ deleteSpace: async (spaceId) => {
122
+ try {
123
+ // Delete all instances in the space first.
124
+ // Note: The Tencent Cloud ES SDK does not provide a DeleteServerlessSpace API.
125
+ // Deleting all instances within the space effectively decommissions it.
126
+ const instancesResponse = await esClient.DescribeServerlessInstances({
127
+ SpaceIds: [spaceId],
128
+ });
129
+ if (instancesResponse.Instances && instancesResponse.Instances.length > 0) {
130
+ for (const instance of instancesResponse.Instances) {
131
+ if (instance.InstanceId) {
132
+ await esClient.DeleteServerlessInstance({
133
+ InstanceId: instance.InstanceId,
134
+ });
135
+ }
136
+ }
137
+ }
138
+ logger_1.logger.info(lang_1.lang.__('TENCENT_ES_SPACE_DELETION_INITIATED', { spaceId }));
139
+ await waitForSpaceDeleted(operations.getSpace, spaceId);
140
+ }
141
+ catch (error) {
142
+ if (error &&
143
+ typeof error === 'object' &&
144
+ 'code' in error &&
145
+ (error.code === 'ResourceNotFound' || error.code === 'InvalidParameterValue')) {
146
+ logger_1.logger.info(lang_1.lang.__('TENCENT_ES_SPACE_DELETED', { spaceId }));
147
+ return;
148
+ }
149
+ logger_1.logger.error(lang_1.lang.__('TENCENT_ES_SPACE_DELETE_FAILED', { error: String(error) }));
150
+ throw error;
151
+ }
152
+ },
153
+ };
154
+ return operations;
155
+ };
156
+ exports.createTencentEsOperations = createTencentEsOperations;
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.createTencentClient = void 0;
43
+ const tencentcloud = __importStar(require("tencentcloud-sdk-nodejs-scf"));
44
+ const cynosdb = __importStar(require("tencentcloud-sdk-nodejs-cynosdb"));
45
+ const tencentEs = __importStar(require("tencentcloud-sdk-nodejs-es"));
46
+ const cos_nodejs_sdk_v5_1 = __importDefault(require("cos-nodejs-sdk-v5"));
47
+ const scfOperations_1 = require("./scfOperations");
48
+ const cosOperations_1 = require("./cosOperations");
49
+ const tdsqlcOperations_1 = require("./tdsqlcOperations");
50
+ const esOperations_1 = require("./esOperations");
51
+ __exportStar(require("./types"), exports);
52
+ const ScfClient = tencentcloud.scf.v20180416.Client;
53
+ const CynosdbClient = cynosdb.cynosdb.v20190107.Client;
54
+ const EsClient = tencentEs.es.v20180416.Client;
55
+ // Initialize SDK clients (internal)
56
+ const initializeSdkClients = (context) => {
57
+ const scfClientConfig = {
58
+ credential: {
59
+ secretId: context.accessKeyId,
60
+ secretKey: context.accessKeySecret,
61
+ },
62
+ region: context.region,
63
+ profile: {
64
+ httpProfile: {
65
+ endpoint: 'scf.tencentcloudapi.com',
66
+ },
67
+ },
68
+ };
69
+ const scfClient = new ScfClient(scfClientConfig);
70
+ const cosClient = new cos_nodejs_sdk_v5_1.default({
71
+ SecretId: context.accessKeyId,
72
+ SecretKey: context.accessKeySecret,
73
+ });
74
+ const cynosdbClientConfig = {
75
+ credential: {
76
+ secretId: context.accessKeyId,
77
+ secretKey: context.accessKeySecret,
78
+ },
79
+ region: context.region,
80
+ profile: {
81
+ httpProfile: {
82
+ endpoint: 'cynosdb.tencentcloudapi.com',
83
+ },
84
+ },
85
+ };
86
+ const cynosdbClient = new CynosdbClient(cynosdbClientConfig);
87
+ const esClientConfig = {
88
+ credential: {
89
+ secretId: context.accessKeyId,
90
+ secretKey: context.accessKeySecret,
91
+ },
92
+ region: context.region,
93
+ profile: {
94
+ httpProfile: {
95
+ endpoint: 'es.tencentcloudapi.com',
96
+ },
97
+ },
98
+ };
99
+ const esClient = new EsClient(esClientConfig);
100
+ return {
101
+ scf: scfClient,
102
+ cos: cosClient,
103
+ cynosdb: cynosdbClient,
104
+ es: esClient,
105
+ };
106
+ };
107
+ const createTencentClient = (context) => {
108
+ const sdkClients = initializeSdkClients(context);
109
+ return {
110
+ scf: (0, scfOperations_1.createScfOperations)(sdkClients.scf),
111
+ cos: (0, cosOperations_1.createCosOperations)(sdkClients.cos),
112
+ tdsqlc: (0, tdsqlcOperations_1.createTdsqlcOperations)(sdkClients.cynosdb, context),
113
+ es: (0, esOperations_1.createTencentEsOperations)(sdkClients.es, context),
114
+ };
115
+ };
116
+ exports.createTencentClient = createTencentClient;
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createScfOperations = void 0;
4
+ const createScfOperations = (scfClient) => ({
5
+ createFunction: async (config, codeBase64) => {
6
+ const params = {
7
+ FunctionName: config.FunctionName,
8
+ Code: {
9
+ ZipFile: codeBase64,
10
+ },
11
+ Handler: config.Handler,
12
+ Runtime: config.Runtime,
13
+ MemorySize: config.MemorySize,
14
+ Timeout: config.Timeout,
15
+ ...(config.Environment && { Environment: config.Environment }),
16
+ };
17
+ await scfClient.CreateFunction(params);
18
+ },
19
+ getFunction: async (functionName) => {
20
+ try {
21
+ const params = {
22
+ FunctionName: functionName,
23
+ };
24
+ const response = await scfClient.GetFunction(params);
25
+ if (!response || !response.FunctionName) {
26
+ return null;
27
+ }
28
+ const environment = response.Environment?.Variables
29
+ ? {
30
+ Variables: response.Environment.Variables.map((v) => ({
31
+ Key: v.Key || '',
32
+ Value: v.Value || '',
33
+ })),
34
+ }
35
+ : undefined;
36
+ const triggers = response.Triggers?.map((t) => ({
37
+ ModTime: t.ModTime || '',
38
+ Type: t.Type || '',
39
+ TriggerDesc: t.TriggerDesc || '',
40
+ TriggerName: t.TriggerName || '',
41
+ AddTime: t.AddTime || '',
42
+ Enable: t.Enable || 0,
43
+ CustomArgument: t.CustomArgument,
44
+ AvailableStatus: t.AvailableStatus,
45
+ ResourceId: t.ResourceId,
46
+ BindStatus: t.BindStatus,
47
+ TriggerAttribute: t.TriggerAttribute,
48
+ Qualifier: t.Qualifier,
49
+ Description: t.Description,
50
+ }));
51
+ const tags = response.Tags?.map((t) => ({
52
+ Key: t.Key || '',
53
+ Value: t.Value || '',
54
+ }));
55
+ return {
56
+ FunctionName: response.FunctionName || '',
57
+ Runtime: response.Runtime || '',
58
+ Handler: response.Handler || '',
59
+ MemorySize: response.MemorySize || 128,
60
+ Timeout: response.Timeout || 3,
61
+ Environment: environment,
62
+ ModTime: response.ModTime,
63
+ CodeSha256: undefined,
64
+ CodeInfo: response.CodeInfo,
65
+ Description: response.Description,
66
+ Triggers: triggers,
67
+ CodeSize: response.CodeSize,
68
+ FunctionVersion: response.FunctionVersion,
69
+ VpcConfig: response.VpcConfig,
70
+ UseGpu: response.UseGpu,
71
+ CodeResult: response.CodeResult,
72
+ CodeError: response.CodeError,
73
+ ErrNo: response.ErrNo,
74
+ Namespace: response.Namespace,
75
+ Role: response.Role,
76
+ InstallDependency: response.InstallDependency,
77
+ Status: response.Status,
78
+ StatusDesc: response.StatusDesc,
79
+ ClsLogsetId: response.ClsLogsetId,
80
+ ClsTopicId: response.ClsTopicId,
81
+ FunctionId: response.FunctionId,
82
+ Tags: tags,
83
+ EipConfig: response.EipConfig,
84
+ AccessInfo: response.AccessInfo,
85
+ Type: response.Type,
86
+ L5Enable: response.L5Enable,
87
+ Layers: response.Layers,
88
+ DeadLetterConfig: response.DeadLetterConfig,
89
+ AddTime: response.AddTime,
90
+ PublicNetConfig: response.PublicNetConfig,
91
+ OnsEnable: response.OnsEnable,
92
+ CfsConfig: response.CfsConfig,
93
+ AvailableStatus: response.AvailableStatus,
94
+ Qualifier: response.Qualifier,
95
+ InitTimeout: response.InitTimeout,
96
+ StatusReasons: response.StatusReasons,
97
+ AsyncRunEnable: response.AsyncRunEnable,
98
+ TraceEnable: response.TraceEnable,
99
+ ImageConfig: response.ImageConfig,
100
+ ProtocolType: response.ProtocolType,
101
+ ProtocolParams: response.ProtocolParams,
102
+ DnsCache: response.DnsCache,
103
+ IntranetConfig: response.IntranetConfig,
104
+ };
105
+ }
106
+ catch (error) {
107
+ if (error &&
108
+ typeof error === 'object' &&
109
+ 'code' in error &&
110
+ error.code === 'ResourceNotFound.FunctionName') {
111
+ return null;
112
+ }
113
+ throw error;
114
+ }
115
+ },
116
+ updateFunctionConfiguration: async (config) => {
117
+ const params = {
118
+ FunctionName: config.FunctionName,
119
+ Handler: config.Handler,
120
+ Runtime: config.Runtime,
121
+ MemorySize: config.MemorySize,
122
+ Timeout: config.Timeout,
123
+ ...(config.Environment && { Environment: config.Environment }),
124
+ };
125
+ await scfClient.UpdateFunctionConfiguration(params);
126
+ },
127
+ updateFunctionCode: async (functionName, codeBase64) => {
128
+ const params = {
129
+ FunctionName: functionName,
130
+ ZipFile: codeBase64,
131
+ };
132
+ await scfClient.UpdateFunctionCode(params);
133
+ },
134
+ deleteFunction: async (functionName) => {
135
+ const params = {
136
+ FunctionName: functionName,
137
+ };
138
+ await scfClient.DeleteFunction(params);
139
+ },
140
+ });
141
+ exports.createScfOperations = createScfOperations;