@geek-fun/serverlessinsight 0.8.2 → 0.8.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 (119) hide show
  1. package/.serverlessinsight/state-cdn-flow-app-cdn-flow-service.json.backup +14 -0
  2. package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +14 -0
  3. package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +348 -0
  4. package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +14 -0
  5. package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +114 -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 +3 -1
  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 +327 -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 +56 -26
  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 +9 -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 +6 -3
  41. package/dist/src/common/stateBackend/saasStateBackend.js +266 -0
  42. package/dist/src/common/stateManager.js +135 -13
  43. package/dist/src/common/tencentClient/cosOperations.js +180 -3
  44. package/dist/src/common/tencentClient/esOperations.js +110 -46
  45. package/dist/src/common/tencentClient/index.js +22 -1
  46. package/dist/src/common/tencentClient/scfOperations.js +255 -133
  47. package/dist/src/common/tencentClient/tdsqlcClusterMapper.js +81 -0
  48. package/dist/src/common/tencentClient/tdsqlcOperations.js +93 -99
  49. package/dist/src/common/triggerMapper.js +36 -0
  50. package/dist/src/common/volcengineClient/apigwOperations.js +539 -159
  51. package/dist/src/common/volcengineClient/iamOperations.js +58 -48
  52. package/dist/src/common/volcengineClient/index.js +46 -21
  53. package/dist/src/common/volcengineClient/stsOperations.js +32 -0
  54. package/dist/src/common/volcengineClient/tlsOperations.js +229 -178
  55. package/dist/src/common/volcengineClient/tosOperations.js +78 -19
  56. package/dist/src/common/volcengineClient/vefaasOperations.js +272 -54
  57. package/dist/src/lang/en.js +84 -0
  58. package/dist/src/lang/zh-CN.js +84 -0
  59. package/dist/src/parser/eventParser.js +2 -0
  60. package/dist/src/parser/functionParser.js +96 -65
  61. package/dist/src/parser/index.js +7 -4
  62. package/dist/src/stack/aliyunStack/apigwExecutor.js +39 -1
  63. package/dist/src/stack/aliyunStack/apigwPlanner.js +14 -10
  64. package/dist/src/stack/aliyunStack/apigwResource.js +216 -124
  65. package/dist/src/stack/aliyunStack/apigwTypes.js +16 -3
  66. package/dist/src/stack/aliyunStack/databaseExecutor.js +39 -1
  67. package/dist/src/stack/aliyunStack/databasePlanner.js +13 -1
  68. package/dist/src/stack/aliyunStack/databaseResource.js +135 -40
  69. package/dist/src/stack/aliyunStack/deployer.js +2 -2
  70. package/dist/src/stack/aliyunStack/destroyer.js +2 -2
  71. package/dist/src/stack/aliyunStack/fc3Executor.js +25 -2
  72. package/dist/src/stack/aliyunStack/fc3Planner.js +11 -1
  73. package/dist/src/stack/aliyunStack/fc3Resource.js +327 -64
  74. package/dist/src/stack/aliyunStack/ossExecutor.js +39 -1
  75. package/dist/src/stack/aliyunStack/ossPlanner.js +15 -1
  76. package/dist/src/stack/aliyunStack/ossResource.js +267 -219
  77. package/dist/src/stack/aliyunStack/tablestoreExecutor.js +39 -1
  78. package/dist/src/stack/aliyunStack/tablestorePlanner.js +13 -1
  79. package/dist/src/stack/aliyunStack/tablestoreResource.js +54 -20
  80. package/dist/src/stack/alreadyExists.js +26 -0
  81. package/dist/src/stack/ownershipTag.js +40 -0
  82. package/dist/src/stack/rfsStack/index.js +3 -1
  83. package/dist/src/stack/scfStack/cosExecutor.js +39 -1
  84. package/dist/src/stack/scfStack/cosPlanner.js +11 -1
  85. package/dist/src/stack/scfStack/cosResource.js +167 -64
  86. package/dist/src/stack/scfStack/deployer.js +2 -2
  87. package/dist/src/stack/scfStack/destroyer.js +2 -2
  88. package/dist/src/stack/scfStack/esServerlessExecutor.js +39 -1
  89. package/dist/src/stack/scfStack/esServerlessPlanner.js +11 -1
  90. package/dist/src/stack/scfStack/esServerlessResource.js +88 -23
  91. package/dist/src/stack/scfStack/scfExecutor.js +39 -1
  92. package/dist/src/stack/scfStack/scfPlanner.js +12 -2
  93. package/dist/src/stack/scfStack/scfResource.js +484 -14
  94. package/dist/src/stack/scfStack/tdsqlcExecutor.js +39 -1
  95. package/dist/src/stack/scfStack/tdsqlcPlanner.js +12 -1
  96. package/dist/src/stack/scfStack/tdsqlcResource.js +95 -16
  97. package/dist/src/stack/scfStack/tdsqlcTypes.js +5 -1
  98. package/dist/src/stack/volcengineStack/apigwExecutor.js +39 -1
  99. package/dist/src/stack/volcengineStack/apigwPlanner.js +25 -53
  100. package/dist/src/stack/volcengineStack/apigwResource.js +418 -222
  101. package/dist/src/stack/volcengineStack/apigwTypes.js +76 -66
  102. package/dist/src/stack/volcengineStack/deployer.js +49 -14
  103. package/dist/src/stack/volcengineStack/destroyer.js +1 -1
  104. package/dist/src/stack/volcengineStack/index.js +1 -2
  105. package/dist/src/stack/volcengineStack/tosExecutor.js +25 -2
  106. package/dist/src/stack/volcengineStack/tosPlanner.js +11 -1
  107. package/dist/src/stack/volcengineStack/tosResource.js +82 -27
  108. package/dist/src/stack/volcengineStack/tosTypes.js +12 -0
  109. package/dist/src/stack/volcengineStack/vefaasExecutor.js +25 -2
  110. package/dist/src/stack/volcengineStack/vefaasPlanner.js +71 -2
  111. package/dist/src/stack/volcengineStack/vefaasResource.js +148 -98
  112. package/dist/src/stack/volcengineStack/vefaasTypes.js +1 -3
  113. package/dist/src/types/domains/backend.js +1 -0
  114. package/dist/src/types/domains/state.js +29 -1
  115. package/dist/src/validator/eventSchema.js +10 -0
  116. package/dist/src/validator/functionSchema.js +37 -12
  117. package/dist/src/validator/iacSchema.js +1 -0
  118. package/dist/tsconfig.tsbuildinfo +1 -1
  119. package/package.json +3 -1
@@ -3,254 +3,305 @@ 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
+ };
11
87
  const createTlsOperations = (tlsClient) => {
12
- return {
88
+ const operations = {
13
89
  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: {
90
+ try {
91
+ const response = await tlsClient.CreateProject({
20
92
  ProjectName: config.projectName,
21
93
  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
- };
94
+ Region: config.region ?? '',
95
+ });
96
+ logger_1.logger.info(lang_1.lang.__('TLS_PROJECT_CREATED', { projectName: config.projectName }));
97
+ return {
98
+ projectId: response.ProjectId,
99
+ projectName: config.projectName,
100
+ description: config.description,
101
+ region: config.region,
102
+ status: 'Active',
103
+ };
104
+ }
105
+ catch (error) {
106
+ if (isAlreadyExistsError(error)) {
107
+ logger_1.logger.warn(lang_1.lang.__('TLS_PROJECT_ALREADY_EXISTS', { projectName: config.projectName }));
108
+ const existing = await operations.getProject(config.projectName);
109
+ if (existing) {
110
+ return existing;
111
+ }
112
+ return {
113
+ projectName: config.projectName,
114
+ description: config.description,
115
+ region: config.region,
116
+ status: 'Active',
117
+ };
118
+ }
119
+ throw error;
120
+ }
35
121
  },
36
122
  getProject: async (projectName) => {
37
123
  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 || {});
124
+ const response = await tlsClient.DescribeProjects({ ProjectName: projectName });
125
+ const project = response.Projects?.find((p) => p.ProjectName === projectName);
126
+ if (!project) {
127
+ return null;
128
+ }
46
129
  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,
130
+ projectId: project.ProjectId,
131
+ projectName: project.ProjectName,
132
+ description: project.Description,
133
+ region: undefined,
134
+ createTime: project.CreateTime,
135
+ status: 'Active',
53
136
  };
54
137
  }
55
138
  catch (error) {
56
- if (error && typeof error === 'object' && 'code' in error) {
57
- if (error.code === 'ProjectNotFound' || error.code === 'ResourceNotFound') {
58
- return null;
59
- }
139
+ if (isNotFoundError(error)) {
140
+ return null;
60
141
  }
61
142
  throw error;
62
143
  }
63
144
  },
64
145
  deleteProject: async (projectName) => {
65
146
  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
- });
147
+ const existing = await operations.getProject(projectName);
148
+ if (!existing?.projectId) {
149
+ logger_1.logger.warn(lang_1.lang.__('TLS_PROJECT_NOT_FOUND', { projectName }));
150
+ return;
151
+ }
152
+ await tlsClient.DeleteProject({ ProjectId: existing.projectId });
73
153
  logger_1.logger.info(lang_1.lang.__('TLS_PROJECT_DELETED', { projectName }));
74
154
  }
75
155
  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
- }
156
+ if (isNotFoundError(error)) {
157
+ logger_1.logger.warn(lang_1.lang.__('TLS_PROJECT_NOT_FOUND', { projectName }));
158
+ return;
81
159
  }
82
160
  throw error;
83
161
  }
84
162
  },
85
163
  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,
164
+ try {
165
+ const project = await operations.getProject(config.projectName);
166
+ if (!project?.projectId) {
167
+ throw new Error(lang_1.lang.__('TLS_PROJECT_NOT_FOUND', { projectName: config.projectName }));
168
+ }
169
+ const response = await tlsClient.CreateTopic({
170
+ ProjectId: project.projectId,
93
171
  TopicName: config.topicName,
94
172
  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
- };
173
+ Ttl: config.ttl ?? 30,
174
+ ShardCount: 1,
175
+ });
176
+ logger_1.logger.info(lang_1.lang.__('TLS_TOPIC_CREATED', { topicName: config.topicName }));
177
+ return {
178
+ topicId: response.TopicId,
179
+ topicName: config.topicName,
180
+ projectName: config.projectName,
181
+ description: config.description,
182
+ ttl: config.ttl ?? 30,
183
+ status: 'Active',
184
+ };
185
+ }
186
+ catch (error) {
187
+ if (isAlreadyExistsError(error)) {
188
+ logger_1.logger.warn(lang_1.lang.__('TLS_TOPIC_ALREADY_EXISTS', { topicName: config.topicName }));
189
+ const existing = await operations.getTopic(config.projectName, config.topicName);
190
+ if (existing) {
191
+ return existing;
192
+ }
193
+ return {
194
+ topicName: config.topicName,
195
+ projectName: config.projectName,
196
+ description: config.description,
197
+ ttl: config.ttl ?? 30,
198
+ status: 'Active',
199
+ };
200
+ }
201
+ throw error;
202
+ }
109
203
  },
110
204
  getTopic: async (projectName, topicName) => {
111
205
  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
- },
206
+ const project = await operations.getProject(projectName);
207
+ if (!project?.projectId) {
208
+ return null;
209
+ }
210
+ const response = await tlsClient.DescribeTopics({
211
+ ProjectId: project.projectId,
212
+ TopicName: topicName,
121
213
  });
122
- const data = (response.Result || {});
214
+ const topic = response.Topics?.find((t) => t.TopicName === topicName);
215
+ if (!topic) {
216
+ return null;
217
+ }
123
218
  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,
219
+ topicId: topic.TopicId,
220
+ topicName: topic.TopicName,
221
+ projectName,
222
+ description: topic.Description,
223
+ ttl: topic.Ttl,
224
+ createTime: topic.CreateTime,
225
+ status: 'Active',
131
226
  };
132
227
  }
133
228
  catch (error) {
134
- if (error && typeof error === 'object' && 'code' in error) {
135
- if (error.code === 'TopicNotFound' || error.code === 'ResourceNotFound') {
136
- return null;
137
- }
229
+ if (isNotFoundError(error)) {
230
+ return null;
138
231
  }
139
232
  throw error;
140
233
  }
141
234
  },
142
235
  deleteTopic: async (projectName, topicName) => {
143
236
  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
- });
237
+ const existing = await operations.getTopic(projectName, topicName);
238
+ if (!existing?.topicId) {
239
+ logger_1.logger.warn(lang_1.lang.__('TLS_TOPIC_NOT_FOUND', { topicName }));
240
+ return;
241
+ }
242
+ await tlsClient.DeleteTopic({ TopicId: existing.topicId });
154
243
  logger_1.logger.info(lang_1.lang.__('TLS_TOPIC_DELETED', { topicName }));
155
244
  }
156
245
  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
- }
246
+ if (isNotFoundError(error)) {
247
+ logger_1.logger.warn(lang_1.lang.__('TLS_TOPIC_NOT_FOUND', { topicName }));
248
+ return;
162
249
  }
163
250
  throw error;
164
251
  }
165
252
  },
166
253
  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
254
+ try {
255
+ const topic = await operations.getTopic(config.projectName, config.topicName);
256
+ if (!topic?.topicId) {
257
+ throw new Error(lang_1.lang.__('TLS_TOPIC_NOT_FOUND', { topicName: config.topicName }));
258
+ }
259
+ await tlsClient.CreateIndex({
260
+ TopicId: topic.topicId,
261
+ FullText: config.fullTextIndex
176
262
  ? {
177
263
  Delimiter: config.fullTextIndex.delimiter ?? ' ,.?;!\n\t',
178
264
  CaseSensitive: config.fullTextIndex.caseSensitive ?? false,
179
265
  }
180
266
  : undefined,
181
- KeyValueIndex: config.keyValueIndex,
182
- },
183
- });
184
- logger_1.logger.info(lang_1.lang.__('TLS_INDEX_CREATED', { topicName: config.topicName }));
185
- },
186
- deleteIndex: async (projectName, topicName) => {
187
- 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
- },
267
+ KeyValue: config.keyValueIndex?.map((kv) => ({
268
+ Key: kv.key,
269
+ Value: { ValueType: kv.type, SqlFlag: true },
270
+ })),
197
271
  });
198
- logger_1.logger.info(lang_1.lang.__('TLS_INDEX_DELETED', { topicName }));
272
+ logger_1.logger.info(lang_1.lang.__('TLS_INDEX_CREATED', { topicName: config.topicName }));
199
273
  }
200
274
  catch (error) {
201
- if (error && typeof error === 'object' && 'code' in error) {
202
- if (error.code === 'IndexNotFound' || error.code === 'ResourceNotFound') {
203
- return;
204
- }
275
+ if (isAlreadyExistsError(error)) {
276
+ logger_1.logger.warn(lang_1.lang.__('TLS_INDEX_ALREADY_EXISTS', { topicName: config.topicName }));
277
+ return;
205
278
  }
206
279
  throw error;
207
280
  }
208
281
  },
209
- 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 },
217
- });
218
- const data = (project.Result || {});
219
- const status = data.Status;
220
- if (status === 'Active') {
282
+ deleteIndex: async (projectName, topicName) => {
283
+ try {
284
+ const topic = await operations.getTopic(projectName, topicName);
285
+ if (!topic?.topicId) {
221
286
  return;
222
287
  }
223
- if (status === 'Failed' || status === 'Error') {
224
- throw new Error(lang_1.lang.__('TLS_PROJECT_FAILED', { projectName }));
225
- }
226
- await delay(WAIT_INTERVAL_MS);
288
+ await tlsClient.DeleteIndex({ TopicId: topic.topicId });
289
+ logger_1.logger.info(lang_1.lang.__('TLS_INDEX_DELETED', { topicName }));
227
290
  }
228
- throw new Error(lang_1.lang.__('TLS_PROJECT_TIMEOUT', { projectName }));
229
- },
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
- },
241
- });
242
- const data = (topic.Result || {});
243
- const status = data.Status;
244
- if (status === 'Active') {
291
+ catch (error) {
292
+ if (isNotFoundError(error)) {
245
293
  return;
246
294
  }
247
- if (status === 'Failed' || status === 'Error') {
248
- throw new Error(lang_1.lang.__('TLS_TOPIC_FAILED', { topicName }));
249
- }
250
- await delay(WAIT_INTERVAL_MS);
295
+ throw error;
251
296
  }
252
- throw new Error(lang_1.lang.__('TLS_TOPIC_TIMEOUT', { topicName }));
297
+ },
298
+ waitForProject: async (projectName) => {
299
+ await waitForProjectReady(operations.getProject, projectName);
300
+ },
301
+ waitForTopic: async (projectName, topicName) => {
302
+ await waitForTopicReady(operations.getTopic, projectName, topicName);
253
303
  },
254
304
  };
305
+ return operations;
255
306
  };
256
307
  exports.createTlsOperations = createTlsOperations;
@@ -67,6 +67,54 @@ const getContentType = (filePath) => {
67
67
  return contentTypes[ext] || 'application/octet-stream';
68
68
  };
69
69
  const createTosOperations = (client, _region) => {
70
+ // Map every field GetBucketInfo returns so state keeps maximum resource
71
+ // detail (owner, project, bucket type, AZ redundancy, S3 endpoints,
72
+ // versioning/acceleration toggles, server-side encryption config).
73
+ const mapBucketInfo = (bucketName, bucketData) => {
74
+ const owner = bucketData.Owner;
75
+ const sse = bucketData.ServerSideEncryptionConfiguration;
76
+ const sseRules = sse?.Rule;
77
+ return {
78
+ name: bucketName,
79
+ location: bucketData.Location,
80
+ creationDate: bucketData.CreationDate,
81
+ storageClass: bucketData.StorageClass,
82
+ extranetEndpoint: bucketData.ExtranetEndpoint,
83
+ intranetEndpoint: bucketData.IntranetEndpoint,
84
+ acl: bucketData.ACL,
85
+ owner: owner
86
+ ? {
87
+ id: owner.ID,
88
+ displayName: owner.DisplayName,
89
+ }
90
+ : undefined,
91
+ projectName: bucketData.ProjectName,
92
+ type: bucketData.Type,
93
+ azRedundancy: bucketData.AzRedundancy,
94
+ extranetS3Endpoint: bucketData.ExtranetS3Endpoint,
95
+ intranetS3Endpoint: bucketData.IntranetS3Endpoint,
96
+ versioning: bucketData.Versioning,
97
+ crossRegionReplication: bucketData.CrossRegionReplication,
98
+ transferAcceleration: bucketData.TransferAcceleration,
99
+ accessMonitor: bucketData.AccessMonitor,
100
+ serverSideEncryptionConfiguration: sseRules
101
+ ? {
102
+ rule: sseRules.map((rule) => {
103
+ const applyDefault = rule.ApplyServerSideEncryptionByDefault;
104
+ return {
105
+ applyServerSideEncryptionByDefault: applyDefault
106
+ ? {
107
+ sseAlgorithm: applyDefault.SSEAlgorithm,
108
+ kmsMasterKeyId: applyDefault.KMSMasterKeyID ??
109
+ applyDefault.KMSMasterKeyId,
110
+ }
111
+ : undefined,
112
+ };
113
+ }),
114
+ }
115
+ : undefined,
116
+ };
117
+ };
70
118
  return {
71
119
  createBucket: async (config) => {
72
120
  if (!client) {
@@ -81,13 +129,19 @@ const createTosOperations = (client, _region) => {
81
129
  if (config.storageClass) {
82
130
  params.StorageClass = config.storageClass;
83
131
  }
132
+ // TOS CreateBucket accepts bucket tags via the x-tos-tagging HTTP header,
133
+ // formatted as URL-encoded key=value pairs joined by '&' (S3-compatible).
134
+ const headers = {
135
+ 'content-type': 'application/xml',
136
+ };
137
+ if (config.Tags && config.Tags.length > 0) {
138
+ headers['x-tos-tagging'] = config.Tags.map((t) => `${encodeURIComponent(t.Key)}=${encodeURIComponent(t.Value)}`).join('&');
139
+ }
84
140
  await client.fetchOpenAPI({
85
141
  Action: 'CreateBucket',
86
142
  Version: '2018-08-01',
87
143
  method: 'PUT',
88
- headers: {
89
- 'content-type': 'application/xml',
90
- },
144
+ headers,
91
145
  query: params,
92
146
  });
93
147
  logger_1.logger.info(lang_1.lang.__('TOS_BUCKET_CREATED', { bucketName: config.bucketName }));
@@ -126,15 +180,7 @@ const createTosOperations = (client, _region) => {
126
180
  });
127
181
  const result = (response.Result || {});
128
182
  const bucketData = (result.BucketInfo || {});
129
- return {
130
- name: config.bucketName,
131
- location: bucketData.Location,
132
- creationDate: bucketData.CreationDate,
133
- storageClass: bucketData.StorageClass,
134
- extranetEndpoint: bucketData.ExtranetEndpoint,
135
- intranetEndpoint: bucketData.IntranetEndpoint,
136
- acl: bucketData.ACL,
137
- };
183
+ return mapBucketInfo(config.bucketName, bucketData);
138
184
  })();
139
185
  return bucketInfo;
140
186
  },
@@ -178,15 +224,28 @@ const createTosOperations = (client, _region) => {
178
224
  catch {
179
225
  // Website config may not exist
180
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 }));
241
+ }
242
+ catch {
243
+ // Bucket tagging may not be configured
244
+ }
181
245
  return {
182
- name: bucketName,
183
- location: bucketData.Location,
184
- creationDate: bucketData.CreationDate,
185
- storageClass: bucketData.StorageClass,
186
- extranetEndpoint: bucketData.ExtranetEndpoint,
187
- intranetEndpoint: bucketData.IntranetEndpoint,
188
- acl: bucketData.ACL,
246
+ ...mapBucketInfo(bucketName, bucketData),
189
247
  websiteConfig,
248
+ Tags: tags,
190
249
  };
191
250
  }
192
251
  catch (error) {