@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
@@ -3,254 +3,388 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTlsOperations = void 0;
4
4
  const logger_1 = require("../logger");
5
5
  const lang_1 = require("../../lang");
6
+ const polling_1 = require("../polling");
6
7
  const WAIT_INTERVAL_MS = 5000;
7
8
  const MAX_WAIT_ATTEMPTS = 30;
8
- const delay = (ms) => new Promise((resolve) => {
9
- setTimeout(resolve, ms);
10
- });
9
+ const waitForProjectReady = async (getProject, projectName) => {
10
+ try {
11
+ await (0, polling_1.pollUntil)({
12
+ description: `TLS project ${projectName} to be ready`,
13
+ fetch: async () => {
14
+ const project = await getProject(projectName);
15
+ if (!project) {
16
+ throw new Error(lang_1.lang.__('TLS_PROJECT_NOT_FOUND', { projectName }));
17
+ }
18
+ if (project.status === 'Failed' || project.status === 'Error') {
19
+ throw new Error(lang_1.lang.__('TLS_PROJECT_FAILED', { projectName }));
20
+ }
21
+ return project;
22
+ },
23
+ isDone: (project) => project?.status === 'Active',
24
+ intervalMs: WAIT_INTERVAL_MS,
25
+ maxAttempts: MAX_WAIT_ATTEMPTS,
26
+ });
27
+ }
28
+ catch (e) {
29
+ if (e instanceof polling_1.PollingTimeoutError) {
30
+ throw new Error(lang_1.lang.__('TLS_PROJECT_TIMEOUT', { projectName }), { cause: e });
31
+ }
32
+ throw e;
33
+ }
34
+ };
35
+ const waitForTopicReady = async (getTopic, projectName, topicName) => {
36
+ try {
37
+ await (0, polling_1.pollUntil)({
38
+ description: `TLS topic ${topicName} to be ready`,
39
+ fetch: async () => {
40
+ const topic = await getTopic(projectName, topicName);
41
+ if (!topic) {
42
+ throw new Error(lang_1.lang.__('TLS_TOPIC_NOT_FOUND', { topicName }));
43
+ }
44
+ return topic;
45
+ },
46
+ isDone: (topic) => !!topic?.topicId,
47
+ intervalMs: WAIT_INTERVAL_MS,
48
+ maxAttempts: MAX_WAIT_ATTEMPTS,
49
+ });
50
+ }
51
+ catch (e) {
52
+ if (e instanceof polling_1.PollingTimeoutError) {
53
+ throw new Error(lang_1.lang.__('TLS_TOPIC_TIMEOUT', { topicName }), { cause: e });
54
+ }
55
+ throw e;
56
+ }
57
+ };
58
+ const extractErrorCode = (error) => {
59
+ if (error && typeof error === 'object') {
60
+ const candidate = error;
61
+ if (candidate.code)
62
+ return candidate.code;
63
+ const nestedCode = candidate.response?.data?.Error?.Code;
64
+ if (nestedCode)
65
+ return nestedCode;
66
+ }
67
+ return undefined;
68
+ };
69
+ const isAlreadyExistsError = (error) => {
70
+ const code = extractErrorCode(error);
71
+ return (code === 'ProjectAlreadyExists' ||
72
+ code === 'TopicAlreadyExists' ||
73
+ code === 'IndexAlreadyExists' ||
74
+ code === 'ResourceAlreadyExists' ||
75
+ code === 'AlreadyExists' ||
76
+ code === 'Conflict' ||
77
+ code === 'Duplicated');
78
+ };
79
+ const isNotFoundError = (error) => {
80
+ const code = extractErrorCode(error);
81
+ return (code === 'ProjectNotFound' ||
82
+ code === 'TopicNotFound' ||
83
+ code === 'IndexNotFound' ||
84
+ code === 'ResourceNotFound' ||
85
+ code === 'NotFound');
86
+ };
87
+ const listTagsForResource = async (tlsClient, resourceType, resourceId) => {
88
+ try {
89
+ const response = await tlsClient.ListTagsForResources({
90
+ ResourceType: resourceType,
91
+ ResourcesIds: [resourceId],
92
+ MaxResults: 50,
93
+ });
94
+ return (response.ResourceTags ?? []).map((rt) => ({ Key: rt.TagKey, Value: rt.TagValue }));
95
+ }
96
+ catch (error) {
97
+ if (isNotFoundError(error)) {
98
+ return [];
99
+ }
100
+ throw error;
101
+ }
102
+ };
11
103
  const createTlsOperations = (tlsClient) => {
12
- return {
104
+ const operations = {
13
105
  createProject: async (config) => {
14
- const response = await tlsClient.fetchOpenAPI({
15
- Action: 'CreateProject',
16
- Version: '2024-01-01',
17
- method: 'POST',
18
- headers: { 'content-type': 'application/json' },
19
- data: {
106
+ try {
107
+ const response = await tlsClient.CreateProject({
20
108
  ProjectName: config.projectName,
21
109
  Description: config.description,
22
- Region: config.region,
23
- },
24
- });
25
- const data = (response.Result || {});
26
- logger_1.logger.info(lang_1.lang.__('TLS_PROJECT_CREATED', { projectName: config.projectName }));
27
- return {
28
- projectId: data.ProjectId,
29
- projectName: config.projectName,
30
- description: config.description,
31
- region: config.region,
32
- createTime: data.CreateTime,
33
- status: data.Status,
34
- };
110
+ Region: config.region ?? '',
111
+ });
112
+ logger_1.logger.info(lang_1.lang.__('TLS_PROJECT_CREATED', { projectName: config.projectName }));
113
+ return {
114
+ projectId: response.ProjectId,
115
+ projectName: config.projectName,
116
+ description: config.description,
117
+ region: config.region,
118
+ status: 'Active',
119
+ created: true,
120
+ };
121
+ }
122
+ catch (error) {
123
+ if (isAlreadyExistsError(error)) {
124
+ logger_1.logger.warn(lang_1.lang.__('TLS_PROJECT_ALREADY_EXISTS', { projectName: config.projectName }));
125
+ const existing = await operations.getProject(config.projectName);
126
+ if (existing) {
127
+ return { ...existing, created: false };
128
+ }
129
+ return {
130
+ projectName: config.projectName,
131
+ description: config.description,
132
+ region: config.region,
133
+ status: 'Active',
134
+ created: false,
135
+ };
136
+ }
137
+ throw error;
138
+ }
35
139
  },
36
140
  getProject: async (projectName) => {
37
141
  try {
38
- const response = await tlsClient.fetchOpenAPI({
39
- Action: 'GetProject',
40
- Version: '2024-01-01',
41
- method: 'POST',
42
- headers: { 'content-type': 'application/json' },
43
- data: { ProjectName: projectName },
44
- });
45
- const data = (response.Result || {});
142
+ const response = await tlsClient.DescribeProjects({ ProjectName: projectName });
143
+ const project = response.Projects?.find((p) => p.ProjectName === projectName);
144
+ if (!project) {
145
+ return null;
146
+ }
46
147
  return {
47
- projectId: data.ProjectId,
48
- projectName: data.ProjectName,
49
- description: data.Description,
50
- region: data.Region,
51
- createTime: data.CreateTime,
52
- status: data.Status,
148
+ projectId: project.ProjectId,
149
+ projectName: project.ProjectName,
150
+ description: project.Description,
151
+ region: undefined,
152
+ createTime: project.CreateTime,
153
+ status: 'Active',
53
154
  };
54
155
  }
55
156
  catch (error) {
56
- if (error && typeof error === 'object' && 'code' in error) {
57
- if (error.code === 'ProjectNotFound' || error.code === 'ResourceNotFound') {
58
- return null;
59
- }
157
+ if (isNotFoundError(error)) {
158
+ return null;
60
159
  }
61
160
  throw error;
62
161
  }
63
162
  },
163
+ getProjectTags: async (projectName) => {
164
+ const project = await operations.getProject(projectName);
165
+ if (!project?.projectId) {
166
+ return [];
167
+ }
168
+ return listTagsForResource(tlsClient, 'project', project.projectId);
169
+ },
64
170
  deleteProject: async (projectName) => {
65
171
  try {
66
- await tlsClient.fetchOpenAPI({
67
- Action: 'DeleteProject',
68
- Version: '2024-01-01',
69
- method: 'POST',
70
- headers: { 'content-type': 'application/json' },
71
- data: { ProjectName: projectName },
72
- });
172
+ const existing = await operations.getProject(projectName);
173
+ if (!existing?.projectId) {
174
+ logger_1.logger.warn(lang_1.lang.__('TLS_PROJECT_NOT_FOUND', { projectName }));
175
+ return;
176
+ }
177
+ await tlsClient.DeleteProject({ ProjectId: existing.projectId });
73
178
  logger_1.logger.info(lang_1.lang.__('TLS_PROJECT_DELETED', { projectName }));
74
179
  }
75
180
  catch (error) {
76
- if (error && typeof error === 'object' && 'code' in error) {
77
- if (error.code === 'ProjectNotFound' || error.code === 'ResourceNotFound') {
78
- logger_1.logger.warn(lang_1.lang.__('TLS_PROJECT_NOT_FOUND', { projectName }));
79
- return;
80
- }
181
+ if (isNotFoundError(error)) {
182
+ logger_1.logger.warn(lang_1.lang.__('TLS_PROJECT_NOT_FOUND', { projectName }));
183
+ return;
81
184
  }
82
185
  throw error;
83
186
  }
84
187
  },
85
188
  createTopic: async (config) => {
86
- const response = await tlsClient.fetchOpenAPI({
87
- Action: 'CreateTopic',
88
- Version: '2024-01-01',
89
- method: 'POST',
90
- headers: { 'content-type': 'application/json' },
91
- data: {
92
- ProjectName: config.projectName,
189
+ try {
190
+ const project = await operations.getProject(config.projectName);
191
+ if (!project?.projectId) {
192
+ throw new Error(lang_1.lang.__('TLS_PROJECT_NOT_FOUND', { projectName: config.projectName }));
193
+ }
194
+ const response = await tlsClient.CreateTopic({
195
+ ProjectId: project.projectId,
93
196
  TopicName: config.topicName,
94
197
  Description: config.description,
95
- TTL: config.ttl ?? 30,
96
- },
97
- });
98
- const data = (response.Result || {});
99
- logger_1.logger.info(lang_1.lang.__('TLS_TOPIC_CREATED', { topicName: config.topicName }));
100
- return {
101
- topicId: data.TopicId,
102
- topicName: config.topicName,
103
- projectName: config.projectName,
104
- description: config.description,
105
- ttl: config.ttl,
106
- createTime: data.CreateTime,
107
- status: data.Status,
108
- };
198
+ Ttl: config.ttl ?? 30,
199
+ ShardCount: 1,
200
+ });
201
+ logger_1.logger.info(lang_1.lang.__('TLS_TOPIC_CREATED', { topicName: config.topicName }));
202
+ return {
203
+ topicId: response.TopicId,
204
+ topicName: config.topicName,
205
+ projectName: config.projectName,
206
+ description: config.description,
207
+ ttl: config.ttl ?? 30,
208
+ status: 'Active',
209
+ };
210
+ }
211
+ catch (error) {
212
+ if (isAlreadyExistsError(error)) {
213
+ logger_1.logger.warn(lang_1.lang.__('TLS_TOPIC_ALREADY_EXISTS', { topicName: config.topicName }));
214
+ const existing = await operations.getTopic(config.projectName, config.topicName);
215
+ if (existing) {
216
+ return existing;
217
+ }
218
+ return {
219
+ topicName: config.topicName,
220
+ projectName: config.projectName,
221
+ description: config.description,
222
+ ttl: config.ttl ?? 30,
223
+ status: 'Active',
224
+ };
225
+ }
226
+ throw error;
227
+ }
109
228
  },
110
229
  getTopic: async (projectName, topicName) => {
111
230
  try {
112
- const response = await tlsClient.fetchOpenAPI({
113
- Action: 'GetTopic',
114
- Version: '2024-01-01',
115
- method: 'POST',
116
- headers: { 'content-type': 'application/json' },
117
- data: {
118
- ProjectName: projectName,
119
- TopicName: topicName,
120
- },
231
+ const project = await operations.getProject(projectName);
232
+ if (!project?.projectId) {
233
+ return null;
234
+ }
235
+ const response = await tlsClient.DescribeTopics({
236
+ ProjectId: project.projectId,
237
+ TopicName: topicName,
121
238
  });
122
- const data = (response.Result || {});
239
+ const topic = response.Topics?.find((t) => t.TopicName === topicName);
240
+ if (!topic) {
241
+ return null;
242
+ }
243
+ const tags = await listTagsForResource(tlsClient, 'topic', topic.TopicId);
123
244
  return {
124
- topicId: data.TopicId,
125
- topicName: data.TopicName,
126
- projectName: data.ProjectName,
127
- description: data.Description,
128
- ttl: data.TTL,
129
- createTime: data.CreateTime,
130
- status: data.Status,
245
+ topicId: topic.TopicId,
246
+ topicName: topic.TopicName,
247
+ projectName,
248
+ description: topic.Description,
249
+ ttl: topic.Ttl,
250
+ createTime: topic.CreateTime,
251
+ status: 'Active',
252
+ tags,
131
253
  };
132
254
  }
133
255
  catch (error) {
134
- if (error && typeof error === 'object' && 'code' in error) {
135
- if (error.code === 'TopicNotFound' || error.code === 'ResourceNotFound') {
136
- return null;
137
- }
256
+ if (isNotFoundError(error)) {
257
+ return null;
258
+ }
259
+ throw error;
260
+ }
261
+ },
262
+ listTopics: async (projectName) => {
263
+ try {
264
+ const project = await operations.getProject(projectName);
265
+ if (!project?.projectId) {
266
+ return [];
267
+ }
268
+ const response = await tlsClient.DescribeTopics({ ProjectId: project.projectId });
269
+ return (response.Topics ?? []).map((topic) => ({
270
+ topicId: topic.TopicId,
271
+ topicName: topic.TopicName,
272
+ projectName,
273
+ description: topic.Description,
274
+ ttl: topic.Ttl,
275
+ createTime: topic.CreateTime,
276
+ status: 'Active',
277
+ }));
278
+ }
279
+ catch (error) {
280
+ if (isNotFoundError(error)) {
281
+ return [];
138
282
  }
139
283
  throw error;
140
284
  }
141
285
  },
142
286
  deleteTopic: async (projectName, topicName) => {
143
287
  try {
144
- await tlsClient.fetchOpenAPI({
145
- Action: 'DeleteTopic',
146
- Version: '2024-01-01',
147
- method: 'POST',
148
- headers: { 'content-type': 'application/json' },
149
- data: {
150
- ProjectName: projectName,
151
- TopicName: topicName,
152
- },
153
- });
288
+ const existing = await operations.getTopic(projectName, topicName);
289
+ if (!existing?.topicId) {
290
+ logger_1.logger.warn(lang_1.lang.__('TLS_TOPIC_NOT_FOUND', { topicName }));
291
+ return;
292
+ }
293
+ await tlsClient.DeleteTopic({ TopicId: existing.topicId });
154
294
  logger_1.logger.info(lang_1.lang.__('TLS_TOPIC_DELETED', { topicName }));
155
295
  }
156
296
  catch (error) {
157
- if (error && typeof error === 'object' && 'code' in error) {
158
- if (error.code === 'TopicNotFound' || error.code === 'ResourceNotFound') {
159
- logger_1.logger.warn(lang_1.lang.__('TLS_TOPIC_NOT_FOUND', { topicName }));
160
- return;
161
- }
297
+ if (isNotFoundError(error)) {
298
+ logger_1.logger.warn(lang_1.lang.__('TLS_TOPIC_NOT_FOUND', { topicName }));
299
+ return;
162
300
  }
163
301
  throw error;
164
302
  }
165
303
  },
166
304
  createIndex: async (config) => {
167
- await tlsClient.fetchOpenAPI({
168
- Action: 'CreateIndex',
169
- Version: '2024-01-01',
170
- method: 'POST',
171
- headers: { 'content-type': 'application/json' },
172
- data: {
173
- ProjectName: config.projectName,
174
- TopicName: config.topicName,
175
- FullTextIndex: config.fullTextIndex
305
+ try {
306
+ const topic = await operations.getTopic(config.projectName, config.topicName);
307
+ if (!topic?.topicId) {
308
+ throw new Error(lang_1.lang.__('TLS_TOPIC_NOT_FOUND', { topicName: config.topicName }));
309
+ }
310
+ await tlsClient.CreateIndex({
311
+ TopicId: topic.topicId,
312
+ FullText: config.fullTextIndex
176
313
  ? {
177
314
  Delimiter: config.fullTextIndex.delimiter ?? ' ,.?;!\n\t',
178
315
  CaseSensitive: config.fullTextIndex.caseSensitive ?? false,
179
316
  }
180
317
  : undefined,
181
- KeyValueIndex: config.keyValueIndex,
182
- },
183
- });
184
- logger_1.logger.info(lang_1.lang.__('TLS_INDEX_CREATED', { topicName: config.topicName }));
318
+ KeyValue: config.keyValueIndex?.map((kv) => ({
319
+ Key: kv.key,
320
+ Value: { ValueType: kv.type, SqlFlag: true },
321
+ })),
322
+ });
323
+ logger_1.logger.info(lang_1.lang.__('TLS_INDEX_CREATED', { topicName: config.topicName }));
324
+ }
325
+ catch (error) {
326
+ if (isAlreadyExistsError(error)) {
327
+ logger_1.logger.warn(lang_1.lang.__('TLS_INDEX_ALREADY_EXISTS', { topicName: config.topicName }));
328
+ return;
329
+ }
330
+ throw error;
331
+ }
185
332
  },
186
333
  deleteIndex: async (projectName, topicName) => {
187
334
  try {
188
- await tlsClient.fetchOpenAPI({
189
- Action: 'DeleteIndex',
190
- Version: '2024-01-01',
191
- method: 'POST',
192
- headers: { 'content-type': 'application/json' },
193
- data: {
194
- ProjectName: projectName,
195
- TopicName: topicName,
196
- },
197
- });
335
+ const topic = await operations.getTopic(projectName, topicName);
336
+ if (!topic?.topicId) {
337
+ return;
338
+ }
339
+ await tlsClient.DeleteIndex({ TopicId: topic.topicId });
198
340
  logger_1.logger.info(lang_1.lang.__('TLS_INDEX_DELETED', { topicName }));
199
341
  }
200
342
  catch (error) {
201
- if (error && typeof error === 'object' && 'code' in error) {
202
- if (error.code === 'IndexNotFound' || error.code === 'ResourceNotFound') {
203
- return;
204
- }
343
+ if (isNotFoundError(error)) {
344
+ return;
205
345
  }
206
346
  throw error;
207
347
  }
208
348
  },
209
349
  waitForProject: async (projectName) => {
210
- for (let attempt = 0; attempt < MAX_WAIT_ATTEMPTS; attempt++) {
211
- const project = await tlsClient.fetchOpenAPI({
212
- Action: 'GetProject',
213
- Version: '2024-01-01',
214
- method: 'POST',
215
- headers: { 'content-type': 'application/json' },
216
- data: { ProjectName: projectName },
350
+ await waitForProjectReady(operations.getProject, projectName);
351
+ },
352
+ waitForTopic: async (projectName, topicName) => {
353
+ await waitForTopicReady(operations.getTopic, projectName, topicName);
354
+ },
355
+ addTags: async (config) => {
356
+ try {
357
+ await tlsClient.AddTagsToResource({
358
+ ResourceType: config.resourceType,
359
+ ResourcesList: config.resourcesList,
360
+ Tags: config.tags.map((tag) => ({ Key: tag.key, Value: tag.value })),
217
361
  });
218
- const data = (project.Result || {});
219
- const status = data.Status;
220
- if (status === 'Active') {
362
+ }
363
+ catch (error) {
364
+ if (isNotFoundError(error)) {
365
+ logger_1.logger.warn(lang_1.lang.__('TLS_TAG_TARGET_NOT_FOUND', { resourceType: config.resourceType }));
221
366
  return;
222
367
  }
223
- if (status === 'Failed' || status === 'Error') {
224
- throw new Error(lang_1.lang.__('TLS_PROJECT_FAILED', { projectName }));
225
- }
226
- await delay(WAIT_INTERVAL_MS);
368
+ throw error;
227
369
  }
228
- throw new Error(lang_1.lang.__('TLS_PROJECT_TIMEOUT', { projectName }));
229
370
  },
230
- waitForTopic: async (projectName, topicName) => {
231
- for (let attempt = 0; attempt < MAX_WAIT_ATTEMPTS; attempt++) {
232
- const topic = await tlsClient.fetchOpenAPI({
233
- Action: 'GetTopic',
234
- Version: '2024-01-01',
235
- method: 'POST',
236
- headers: { 'content-type': 'application/json' },
237
- data: {
238
- ProjectName: projectName,
239
- TopicName: topicName,
240
- },
371
+ removeTags: async (config) => {
372
+ try {
373
+ await tlsClient.RemoveTagsFromResource({
374
+ ResourceType: config.resourceType,
375
+ ResourcesList: config.resourcesList,
376
+ TagKeyList: config.tagKeys,
241
377
  });
242
- const data = (topic.Result || {});
243
- const status = data.Status;
244
- if (status === 'Active') {
378
+ }
379
+ catch (error) {
380
+ if (isNotFoundError(error)) {
381
+ logger_1.logger.warn(lang_1.lang.__('TLS_TAG_TARGET_NOT_FOUND', { resourceType: config.resourceType }));
245
382
  return;
246
383
  }
247
- if (status === 'Failed' || status === 'Error') {
248
- throw new Error(lang_1.lang.__('TLS_TOPIC_FAILED', { topicName }));
249
- }
250
- await delay(WAIT_INTERVAL_MS);
384
+ throw error;
251
385
  }
252
- throw new Error(lang_1.lang.__('TLS_TOPIC_TIMEOUT', { topicName }));
253
386
  },
254
387
  };
388
+ return operations;
255
389
  };
256
390
  exports.createTlsOperations = createTlsOperations;