@geek-fun/serverlessinsight 0.5.5 → 0.5.7

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 (33) hide show
  1. package/README.md +12 -10
  2. package/dist/package.json +2 -1
  3. package/dist/src/commands/deploy.js +74 -2
  4. package/dist/src/commands/index.js +17 -16
  5. package/dist/src/commands/show.js +302 -0
  6. package/dist/src/common/aliyunClient/apigwOperations.js +6 -22
  7. package/dist/src/common/aliyunClient/index.js +3 -2
  8. package/dist/src/common/aliyunClient/ossOperations.js +126 -1
  9. package/dist/src/common/constants.js +2 -3
  10. package/dist/src/common/context.js +4 -1
  11. package/dist/src/common/credentials.js +9 -3
  12. package/dist/src/common/domainUtils.js +121 -0
  13. package/dist/src/common/iacHelper.js +1 -8
  14. package/dist/src/common/stateBackend/cosStateBackend.js +16 -188
  15. package/dist/src/common/stateBackend/index.js +2 -0
  16. package/dist/src/common/stateBackend/lockUtils.js +55 -0
  17. package/dist/src/common/stateBackend/ossStateBackend.js +27 -199
  18. package/dist/src/common/stateBackend/remoteStateBackend.js +150 -0
  19. package/dist/src/common/tencentClient/cosOperations.js +366 -216
  20. package/dist/src/common/tencentClient/dnspodOperations.js +105 -0
  21. package/dist/src/common/tencentClient/index.js +5 -1
  22. package/dist/src/lang/en.js +30 -0
  23. package/dist/src/lang/zh-CN.js +28 -0
  24. package/dist/src/stack/aliyunStack/apigwResource.js +35 -0
  25. package/dist/src/stack/aliyunStack/ossResource.js +63 -19
  26. package/dist/src/stack/deploy.js +6 -33
  27. package/dist/src/stack/scfStack/cosResource.js +58 -8
  28. package/dist/src/types/domains/state.js +13 -0
  29. package/dist/src/validator/bucketSchema.js +1 -1
  30. package/dist/src/validator/templateRefSchema.js +1 -1
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +2 -1
  33. package/dist/src/commands/template.js +0 -28
@@ -0,0 +1,105 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.createDnsClient = exports.createDnsOperations = void 0;
37
+ const tencentcloud = __importStar(require("tencentcloud-sdk-nodejs-dnspod"));
38
+ const DnspodClient = tencentcloud.dnspod.v20210323.Client;
39
+ const addDomainRecord = (dnsClient) => async (config) => {
40
+ const response = await dnsClient.CreateRecord({
41
+ Domain: config.domainName,
42
+ SubDomain: config.rr,
43
+ RecordType: config.type,
44
+ Value: config.value,
45
+ RecordLine: '默认',
46
+ TTL: config.ttl || 600,
47
+ });
48
+ return String(response.RecordId);
49
+ };
50
+ const deleteDomainRecord = (dnsClient) => async (domainName, recordId) => {
51
+ await dnsClient.DeleteRecord({
52
+ Domain: domainName,
53
+ RecordId: parseInt(recordId, 10),
54
+ });
55
+ };
56
+ const describeDomainRecords = (dnsClient) => async (domainName, rrKeyWord) => {
57
+ const response = await dnsClient.DescribeRecordList({
58
+ Domain: domainName,
59
+ Subdomain: rrKeyWord,
60
+ });
61
+ const records = response.RecordList || [];
62
+ return records.map((record) => ({
63
+ recordId: String(record.RecordId),
64
+ domainName: domainName,
65
+ rr: record.Name,
66
+ type: record.Type,
67
+ value: record.Value,
68
+ ttl: record.TTL,
69
+ status: record.Status,
70
+ }));
71
+ };
72
+ const checkDomainRecordExists = (describeFn) => async (domainName, rr) => {
73
+ try {
74
+ const records = await describeFn(domainName, rr);
75
+ return records.some((record) => record.rr === rr);
76
+ }
77
+ catch {
78
+ return false;
79
+ }
80
+ };
81
+ const createDnsOperations = (dnsClient) => {
82
+ const describe = describeDomainRecords(dnsClient);
83
+ return {
84
+ addDomainRecord: addDomainRecord(dnsClient),
85
+ deleteDomainRecord: deleteDomainRecord(dnsClient),
86
+ describeDomainRecords: describe,
87
+ checkDomainRecordExists: checkDomainRecordExists(describe),
88
+ };
89
+ };
90
+ exports.createDnsOperations = createDnsOperations;
91
+ const createDnsClient = (context) => {
92
+ return new DnspodClient({
93
+ credential: {
94
+ secretId: context.accessKeyId,
95
+ secretKey: context.accessKeySecret,
96
+ },
97
+ region: '',
98
+ profile: {
99
+ httpProfile: {
100
+ endpoint: 'dnspod.tencentcloudapi.com',
101
+ },
102
+ },
103
+ });
104
+ };
105
+ exports.createDnsClient = createDnsClient;
@@ -48,6 +48,7 @@ const scfOperations_1 = require("./scfOperations");
48
48
  const cosOperations_1 = require("./cosOperations");
49
49
  const tdsqlcOperations_1 = require("./tdsqlcOperations");
50
50
  const esOperations_1 = require("./esOperations");
51
+ const dnspodOperations_1 = require("./dnspodOperations");
51
52
  __exportStar(require("./types"), exports);
52
53
  const ScfClient = tencentcloud.scf.v20180416.Client;
53
54
  const CynosdbClient = cynosdb.cynosdb.v20190107.Client;
@@ -102,15 +103,18 @@ const initializeSdkClients = (context) => {
102
103
  cos: cosClient,
103
104
  cynosdb: cynosdbClient,
104
105
  es: esClient,
106
+ dns: (0, dnspodOperations_1.createDnsClient)(context),
105
107
  };
106
108
  };
107
109
  const createTencentClient = (context) => {
108
110
  const sdkClients = initializeSdkClients(context);
111
+ const dnsOps = (0, dnspodOperations_1.createDnsOperations)(sdkClients.dns);
109
112
  return {
110
113
  scf: (0, scfOperations_1.createScfOperations)(sdkClients.scf),
111
- cos: (0, cosOperations_1.createCosOperations)(sdkClients.cos),
114
+ cos: (0, cosOperations_1.createCosOperations)(sdkClients.cos, context.region, dnsOps),
112
115
  tdsqlc: (0, tdsqlcOperations_1.createTdsqlcOperations)(sdkClients.cynosdb, context),
113
116
  es: (0, esOperations_1.createTencentEsOperations)(sdkClients.es, context),
117
+ dns: dnsOps,
114
118
  };
115
119
  };
116
120
  exports.createTencentClient = createTencentClient;
@@ -101,6 +101,8 @@ exports.en = {
101
101
  GENERATING_PLAN: 'Generating deployment plan...',
102
102
  PLAN_GENERATED: 'Plan generated with',
103
103
  EXECUTING_PLAN: 'Executing deployment plan...',
104
+ DEPLOY_CONFIRMATION: 'Do you want to perform these actions? (yes/no): ',
105
+ DEPLOY_CANCELLED: 'Deployment cancelled.',
104
106
  // TDSQL-C database messages
105
107
  TDSQL_CLUSTER_CREATION_INITIATED: 'TDSQL-C cluster creation initiated',
106
108
  TDSQL_CLUSTER_CREATION_FAILED: 'Failed to create TDSQL-C cluster',
@@ -254,6 +256,34 @@ exports.en = {
254
256
  FC3_CAN_RETRY_DEPLOYMENT: 'You can retry deployment - the system will reuse existing dependent resources',
255
257
  // Bucket resource messages
256
258
  OSS_BUCKET_TRACKED_CAN_RETRY: 'Bucket is tracked in state, you can retry deployment to upload files',
259
+ OSS_DNS_CNAME_CREATED: 'Created DNS CNAME record: {{domain}} -> {{cname}}',
260
+ OSS_DNS_CNAME_EXISTS: 'DNS CNAME record already exists: {{domain}} -> {{cname}}',
261
+ OSS_DNS_CNAME_DELETED: 'Deleted DNS CNAME record for {{domain}}',
262
+ OSS_DNS_CNAME_DELETE_FAILED: 'Failed to delete DNS CNAME record for {{domain}}: {{error}}',
263
+ OSS_DNS_DOMAIN_NOT_MANAGED: 'The domain {{domain}} is not managed by this Aliyun account. ' +
264
+ 'Please manually configure CNAME: {{domain}} -> {{cname}}',
265
+ OSS_DNS_MANUAL_CONFIG_REQUIRED: 'DNS operations not available. Please manually configure CNAME: {{domain}} -> {{cname}}',
266
+ OSS_BUCKET_CNAME_NOT_SUPPORTED: 'Bucket-level CNAME registration requires Aliyun console. ' +
267
+ 'After DNS CNAME is configured, register {{domain}} in OSS console: ' +
268
+ 'https://oss.console.aliyun.com/bucket/oss-{{region}}/{{bucket}}/domain/cname',
269
+ OSS_BUCKET_CNAME_BOUND: 'Bound custom domain to bucket: {{domain}}',
270
+ OSS_BUCKET_CNAME_EXISTS: 'Custom domain already bound to bucket: {{domain}}',
271
+ OSS_BUCKET_CNAME_UNBOUND: 'Unbound custom domain from bucket: {{domain}}',
272
+ OSS_BUCKET_CNAME_BIND_FAILED: 'Failed to bind bucket CNAME: {{error}}',
273
+ OSS_BUCKET_CNAME_UNBIND_FAILED: 'Failed to unbind bucket CNAME: {{error}}',
274
+ OSS_BUCKET_CNAME_NEED_VERIFY: 'Domain ownership verification required. Please add TXT record in DNS console, then retry.',
275
+ // Tencent COS DNS messages
276
+ COS_DNS_CNAME_CREATED: 'Created DNS CNAME record: {{domain}} -> {{cname}}',
277
+ COS_DNS_CNAME_EXISTS: 'DNS CNAME record already exists: {{domain}} -> {{cname}}',
278
+ COS_DNS_CNAME_DELETED: 'Deleted DNS CNAME record for {{domain}}',
279
+ COS_DNS_CNAME_DELETE_FAILED: 'Failed to delete DNS CNAME record for {{domain}}: {{error}}',
280
+ COS_DNS_DOMAIN_NOT_MANAGED: 'The domain {{domain}} is not managed by this Tencent Cloud account. ' +
281
+ 'Please manually configure CNAME: {{domain}} -> {{cname}}',
282
+ COS_DNS_MANUAL_CONFIG_REQUIRED: 'DNS operations not available. Please manually configure CNAME: {{domain}} -> {{cname}}',
283
+ COS_BUCKET_DOMAIN_BOUND: 'Bound custom domain to bucket: {{domain}}',
284
+ COS_BUCKET_DOMAIN_BIND_FAILED: 'Failed to bind bucket domain: {{error}}',
285
+ COS_BUCKET_DOMAIN_UNBOUND: 'Unbound custom domain from bucket: {{domain}}',
286
+ COS_BUCKET_DOMAIN_UNBIND_FAILED: 'Failed to unbind bucket domain: {{error}}',
257
287
  // Dependency graph messages
258
288
  DEPENDENCY_GRAPH_GENERATED: 'Dependency graph generated',
259
289
  EXECUTION_ORDER: 'Execution order',
@@ -101,6 +101,8 @@ exports.zhCN = {
101
101
  GENERATING_PLAN: '正在生成部署计划...',
102
102
  PLAN_GENERATED: '计划已生成,共有',
103
103
  EXECUTING_PLAN: '正在执行部署计划...',
104
+ DEPLOY_CONFIRMATION: '是否执行这些操作?(yes/no): ',
105
+ DEPLOY_CANCELLED: '部署已取消。',
104
106
  // TDSQL-C 数据库消息
105
107
  TDSQL_CLUSTER_CREATION_INITIATED: 'TDSQL-C 集群创建已启动',
106
108
  TDSQL_CLUSTER_CREATION_FAILED: '创建 TDSQL-C 集群失败',
@@ -254,6 +256,32 @@ exports.zhCN = {
254
256
  FC3_CAN_RETRY_DEPLOYMENT: '您可以重试部署 - 系统将复用现有的依赖资源',
255
257
  // Bucket resource messages
256
258
  OSS_BUCKET_TRACKED_CAN_RETRY: '存储桶已在状态中跟踪,您可以重试部署以上传文件',
259
+ OSS_DNS_CNAME_CREATED: '已创建 DNS CNAME 记录: {{domain}} -> {{cname}}',
260
+ OSS_DNS_CNAME_EXISTS: 'DNS CNAME 记录已存在: {{domain}} -> {{cname}}',
261
+ OSS_DNS_CNAME_DELETED: '已删除 DNS CNAME 记录: {{domain}}',
262
+ OSS_DNS_CNAME_DELETE_FAILED: '删除 DNS CNAME 记录失败: {{domain}}: {{error}}',
263
+ OSS_DNS_DOMAIN_NOT_MANAGED: '域名 {{domain}} 不在当前阿里云账号下管理。' + '请手动配置 CNAME: {{domain}} -> {{cname}}',
264
+ OSS_DNS_MANUAL_CONFIG_REQUIRED: 'DNS 操作不可用。请手动配置 CNAME: {{domain}} -> {{cname}}',
265
+ OSS_BUCKET_CNAME_NOT_SUPPORTED: '存储桶级 CNAME 绑定需要在阿里云控制台完成。' +
266
+ 'DNS CNAME 配置后,请在 OSS 控制台注册 {{domain}}: ' +
267
+ 'https://oss.console.aliyun.com/bucket/oss-{{region}}/{{bucket}}/domain/cname',
268
+ OSS_BUCKET_CNAME_BOUND: '已绑定自定义域名到存储桶: {{domain}}',
269
+ OSS_BUCKET_CNAME_EXISTS: '自定义域名已绑定到存储桶: {{domain}}',
270
+ OSS_BUCKET_CNAME_UNBOUND: '已解绑存储桶自定义域名: {{domain}}',
271
+ OSS_BUCKET_CNAME_BIND_FAILED: '绑定存储桶 CNAME 失败: {{error}}',
272
+ OSS_BUCKET_CNAME_UNBIND_FAILED: '解绑存储桶 CNAME 失败: {{error}}',
273
+ OSS_BUCKET_CNAME_NEED_VERIFY: '需要验证域名所有权。请在 DNS 控制台添加 TXT 记录后重试。',
274
+ // Tencent COS DNS messages
275
+ COS_DNS_CNAME_CREATED: '已创建 DNS CNAME 记录: {{domain}} -> {{cname}}',
276
+ COS_DNS_CNAME_EXISTS: 'DNS CNAME 记录已存在: {{domain}} -> {{cname}}',
277
+ COS_DNS_CNAME_DELETED: '已删除 DNS CNAME 记录: {{domain}}',
278
+ COS_DNS_CNAME_DELETE_FAILED: '删除 DNS CNAME 记录失败: {{domain}}: {{error}}',
279
+ COS_DNS_DOMAIN_NOT_MANAGED: '域名 {{domain}} 不在当前腾讯云账号下管理。' + '请手动配置 CNAME: {{domain}} -> {{cname}}',
280
+ COS_DNS_MANUAL_CONFIG_REQUIRED: 'DNS 操作不可用。请手动配置 CNAME: {{domain}} -> {{cname}}',
281
+ COS_BUCKET_DOMAIN_BOUND: '已绑定自定义域名到存储桶: {{domain}}',
282
+ COS_BUCKET_DOMAIN_BIND_FAILED: '绑定存储桶域名失败: {{error}}',
283
+ COS_BUCKET_DOMAIN_UNBOUND: '已解绑存储桶自定义域名: {{domain}}',
284
+ COS_BUCKET_DOMAIN_UNBIND_FAILED: '解绑存储桶域名失败: {{error}}',
257
285
  // Dependency graph messages
258
286
  DEPENDENCY_GRAPH_GENERATED: '依赖图已生成',
259
287
  EXECUTION_ORDER: '执行顺序',
@@ -308,9 +308,12 @@ const deleteApigwResource = async (context, logicalId, state) => {
308
308
  const existingInstances = existingState.instances;
309
309
  const groupInstance = existingInstances.find((i) => i.type === 'ALIYUN_APIGW_GROUP');
310
310
  if (!groupInstance) {
311
+ // Still clean up DNS resources even if group instance is missing
312
+ state = await cleanupDnsRecords(context, logicalId, state);
311
313
  return (0, stateManager_1.removeResource)(state, logicalId);
312
314
  }
313
315
  const groupId = groupInstance.id;
316
+ state = await cleanupDnsRecords(context, logicalId, state);
314
317
  const deployments = existingInstances.filter((i) => i.type === 'ALIYUN_APIGW_DEPLOYMENT');
315
318
  for (const deployment of deployments) {
316
319
  try {
@@ -338,3 +341,35 @@ const deleteApigwResource = async (context, logicalId, state) => {
338
341
  return (0, stateManager_1.removeResource)(state, logicalId);
339
342
  };
340
343
  exports.deleteApigwResource = deleteApigwResource;
344
+ /**
345
+ * Clean up DNS verification records for an API Gateway event
346
+ */
347
+ const cleanupDnsRecords = async (context, eventLogicalId, state) => {
348
+ const client = (0, aliyunClient_1.createAliyunClient)(context);
349
+ const dnsResourceIds = [
350
+ `${eventLogicalId}.dns_verification`,
351
+ `${eventLogicalId}.dns_txt_verification`,
352
+ ];
353
+ for (const dnsResourceId of dnsResourceIds) {
354
+ const dnsState = (0, stateManager_1.getResource)(state, dnsResourceId);
355
+ if (!dnsState) {
356
+ continue;
357
+ }
358
+ const dnsInstance = dnsState.instances[0];
359
+ const recordId = dnsInstance?.id;
360
+ // Only delete if recordId is not 'existing' (which means we didn't create it)
361
+ if (recordId && recordId !== 'existing') {
362
+ try {
363
+ logger_1.logger.info(`Deleting DNS record: ${recordId}`);
364
+ await client.dns.deleteDomainRecord(recordId);
365
+ logger_1.logger.info(`Successfully deleted DNS record: ${recordId}`);
366
+ }
367
+ catch (error) {
368
+ // DNS record might already be deleted or not accessible
369
+ logger_1.logger.warn(`Failed to delete DNS record ${recordId}: ${error}`);
370
+ }
371
+ }
372
+ state = (0, stateManager_1.removeResource)(state, dnsResourceId);
373
+ }
374
+ return state;
375
+ };
@@ -6,13 +6,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.deleteBucketResource = exports.updateBucketResource = exports.readBucketResource = exports.createBucketResource = void 0;
7
7
  const aliyunClient_1 = require("../../common/aliyunClient");
8
8
  const common_1 = require("../../common");
9
+ const types_1 = require("../../types");
9
10
  const ossTypes_1 = require("./ossTypes");
10
11
  const logger_1 = require("../../common/logger");
11
12
  const lang_1 = require("../../lang");
12
13
  const node_path_1 = __importDefault(require("node:path"));
13
14
  const buildOssInstanceFromProvider = (info, sid) => {
14
15
  return {
15
- type: 'ALIYUN_OSS_BUCKET',
16
+ type: types_1.ResourceTypeEnum.ALIYUN_OSS_BUCKET,
16
17
  sid,
17
18
  id: info.name,
18
19
  bucketName: info.name,
@@ -113,15 +114,32 @@ const createBucketResource = async (context, bucket, state) => {
113
114
  const definition = (0, ossTypes_1.extractOssBucketDefinition)(config);
114
115
  const sid = (0, common_1.buildSid)('aliyun', 'oss', context.stage, config.bucketName);
115
116
  const logicalId = `buckets.${bucket.key}`;
116
- // Save state immediately after bucket creation, before file upload
117
+ const instances = [buildOssInstanceFromProvider(bucketInfo, sid)];
117
118
  const partialResourceState = {
118
119
  mode: 'managed',
119
120
  region: context.region,
120
121
  definition,
121
- instances: [buildOssInstanceFromProvider(bucketInfo, sid)],
122
+ instances,
122
123
  lastUpdated: new Date().toISOString(),
123
124
  };
124
125
  state = (0, common_1.setResource)(state, logicalId, partialResourceState);
126
+ let cnameInfo;
127
+ if (bucket.website?.domain) {
128
+ logger_1.logger.info(`Binding custom domain ${bucket.website.domain} to bucket ${config.bucketName}`);
129
+ cnameInfo = await client.oss.bindCustomDomain(config.bucketName, bucket.website.domain);
130
+ if (cnameInfo) {
131
+ const instanceId = cnameInfo.dnsRecordId ?? bucket.website.domain;
132
+ const dnsInstance = {
133
+ sid: (0, common_1.buildSid)('aliyun', 'alidns', context.stage, instanceId),
134
+ id: instanceId,
135
+ type: types_1.ResourceTypeEnum.ALIYUN_OSS_DNS_CNAME,
136
+ domain: bucket.website.domain,
137
+ cname: cnameInfo.cname,
138
+ ...(cnameInfo.dnsRecordId ? { dnsRecordId: cnameInfo.dnsRecordId } : {}),
139
+ };
140
+ instances.push(dnsInstance);
141
+ }
142
+ }
125
143
  // Upload static files if code path is specified
126
144
  if (bucket.website?.code) {
127
145
  try {
@@ -130,23 +148,22 @@ const createBucketResource = async (context, bucket, state) => {
130
148
  // Refresh state after upload to get updated info
131
149
  bucketInfo = await client.oss.getBucket(config.bucketName);
132
150
  if (bucketInfo) {
133
- const updatedResourceState = {
134
- mode: 'managed',
135
- region: context.region,
136
- definition,
137
- instances: [buildOssInstanceFromProvider(bucketInfo, sid)],
138
- lastUpdated: new Date().toISOString(),
139
- };
140
- return (0, common_1.setResource)(state, logicalId, updatedResourceState);
151
+ instances[0] = buildOssInstanceFromProvider(bucketInfo, sid);
141
152
  }
142
153
  }
143
154
  catch (error) {
144
155
  logger_1.logger.error(`Failed to upload files to bucket, but bucket was created and saved to state: ${error}`);
145
156
  logger_1.logger.info(lang_1.lang.__('OSS_BUCKET_TRACKED_CAN_RETRY'));
146
- return state;
147
157
  }
148
158
  }
149
- return state;
159
+ const finalResourceState = {
160
+ mode: 'managed',
161
+ region: context.region,
162
+ definition,
163
+ instances,
164
+ lastUpdated: new Date().toISOString(),
165
+ };
166
+ return (0, common_1.setResource)(state, logicalId, finalResourceState);
150
167
  };
151
168
  exports.createBucketResource = createBucketResource;
152
169
  const readBucketResource = async (context, bucketName) => {
@@ -157,39 +174,66 @@ exports.readBucketResource = readBucketResource;
157
174
  const updateBucketResource = async (context, bucket, state) => {
158
175
  const config = (0, ossTypes_1.bucketToOssBucketConfig)(bucket);
159
176
  const client = (0, aliyunClient_1.createAliyunClient)(context);
160
- // Update ACL if specified
161
177
  if (config.acl) {
162
178
  await client.oss.updateBucketAcl(config.bucketName, config.acl);
163
179
  }
164
- // Update website configuration if specified
165
180
  if (config.websiteConfig) {
166
181
  await client.oss.updateBucketWebsite(config.bucketName, config.websiteConfig);
167
182
  }
168
- // Upload static files if code path is specified
169
183
  if (bucket.website?.code) {
170
184
  const codePath = node_path_1.default.resolve(process.cwd(), bucket.website.code);
171
185
  await client.oss.uploadFiles(config.bucketName, codePath);
172
186
  }
173
- // Refresh state from provider to get all attributes
174
187
  const bucketInfo = await client.oss.getBucket(config.bucketName);
175
188
  if (!bucketInfo) {
176
189
  throw new Error(`Failed to refresh state for bucket: ${config.bucketName}`);
177
190
  }
178
191
  const definition = (0, ossTypes_1.extractOssBucketDefinition)(config);
179
192
  const sid = (0, common_1.buildSid)('aliyun', 'oss', context.stage, config.bucketName);
193
+ const logicalId = `buckets.${bucket.key}`;
194
+ const instances = [buildOssInstanceFromProvider(bucketInfo, sid)];
195
+ const existingState = state.resources[logicalId];
196
+ const existingDnsInstance = existingState?.instances?.find((i) => i.type === types_1.ResourceTypeEnum.ALIYUN_OSS_DNS_CNAME);
197
+ if (bucket.website?.domain) {
198
+ const domainChanged = existingDnsInstance?.domain !== bucket.website.domain;
199
+ if (domainChanged && existingDnsInstance) {
200
+ await client.oss.unbindCustomDomain(config.bucketName, existingDnsInstance.domain, existingDnsInstance.dnsRecordId);
201
+ }
202
+ logger_1.logger.info(`Binding custom domain ${bucket.website.domain} to bucket ${config.bucketName}`);
203
+ const cnameInfo = await client.oss.bindCustomDomain(config.bucketName, bucket.website.domain);
204
+ if (cnameInfo) {
205
+ const instanceId = cnameInfo.dnsRecordId ?? bucket.website.domain;
206
+ const dnsInstance = {
207
+ sid: (0, common_1.buildSid)('aliyun', 'alidns', context.stage, instanceId),
208
+ id: instanceId,
209
+ type: types_1.ResourceTypeEnum.ALIYUN_OSS_DNS_CNAME,
210
+ domain: bucket.website.domain,
211
+ cname: cnameInfo.cname,
212
+ ...(cnameInfo.dnsRecordId ? { dnsRecordId: cnameInfo.dnsRecordId } : {}),
213
+ };
214
+ instances.push(dnsInstance);
215
+ }
216
+ }
217
+ else if (existingDnsInstance) {
218
+ await client.oss.unbindCustomDomain(config.bucketName, existingDnsInstance.domain, existingDnsInstance.dnsRecordId);
219
+ }
180
220
  const resourceState = {
181
221
  mode: 'managed',
182
222
  region: context.region,
183
223
  definition,
184
- instances: [buildOssInstanceFromProvider(bucketInfo, sid)],
224
+ instances,
185
225
  lastUpdated: new Date().toISOString(),
186
226
  };
187
- const logicalId = `buckets.${bucket.key}`;
188
227
  return (0, common_1.setResource)(state, logicalId, resourceState);
189
228
  };
190
229
  exports.updateBucketResource = updateBucketResource;
191
230
  const deleteBucketResource = async (context, bucketName, logicalId, state) => {
192
231
  const client = (0, aliyunClient_1.createAliyunClient)(context);
232
+ const existingState = state.resources[logicalId];
233
+ const dnsInstance = existingState?.instances?.find((i) => i.type === types_1.ResourceTypeEnum.ALIYUN_OSS_DNS_CNAME);
234
+ if (dnsInstance) {
235
+ await client.oss.unbindCustomDomain(bucketName, dnsInstance.domain, dnsInstance.dnsRecordId);
236
+ }
193
237
  try {
194
238
  await client.oss.deleteBucket(bucketName);
195
239
  }
@@ -1,25 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateStackTemplate = exports.deployStack = exports.generateRfsStackTemplate = void 0;
3
+ exports.deployStack = void 0;
4
4
  const common_1 = require("../common");
5
- const rfsStack_1 = require("./rfsStack");
6
5
  const scfStack_1 = require("./scfStack");
7
6
  const aliyunStack_1 = require("./aliyunStack");
8
- const lang_1 = require("../lang");
9
- const generateRfsStackTemplate = (iac) => {
10
- const stack = new rfsStack_1.RfsStack(iac);
11
- const hcl = stack.toHclTerraform();
12
- console.log('HCL:', hcl);
13
- return { template: hcl };
14
- };
15
- exports.generateRfsStackTemplate = generateRfsStackTemplate;
16
- const deployHuawei = async (iac) => {
17
- // For now, Huawei uses the same approach as Aliyun but with different stack
18
- const { template } = (0, exports.generateRfsStackTemplate)(iac);
19
- common_1.logger.info(lang_1.lang.__('DEPLOYING_STACK_PUBLISHING_ASSETS'));
20
- // TODO: Implement Huawei-specific deployment logic
21
- console.log('HCL:', template);
22
- common_1.logger.info(lang_1.lang.__('STACK_DEPLOYED'));
7
+ const deployHuawei = async () => {
8
+ throw new Error('Huawei deployment is not yet implemented. ' +
9
+ 'The provider currently generates HCL templates but does not deploy them. ' +
10
+ 'Please use Aliyun or Tencent providers, or contribute Huawei deployment support.');
23
11
  };
24
12
  const deployStack = async (iac, backend) => {
25
13
  if (iac.provider.name === common_1.ProviderEnum.TENCENT) {
@@ -29,22 +17,7 @@ const deployStack = async (iac, backend) => {
29
17
  await (0, aliyunStack_1.deployAliyunStack)(iac, backend);
30
18
  }
31
19
  else if (iac.provider.name === common_1.ProviderEnum.HUAWEI) {
32
- await deployHuawei(iac);
20
+ await deployHuawei();
33
21
  }
34
22
  };
35
23
  exports.deployStack = deployStack;
36
- const generateStackTemplate = (iac) => {
37
- if (iac.provider.name === common_1.ProviderEnum.ALIYUN) {
38
- // Aliyun now uses state-based deployment, no template generation needed
39
- return { template: {} };
40
- }
41
- else if (iac.provider.name === common_1.ProviderEnum.HUAWEI) {
42
- return (0, exports.generateRfsStackTemplate)(iac);
43
- }
44
- else if (iac.provider.name === common_1.ProviderEnum.TENCENT) {
45
- // Tencent uses state-based deployment, no template generation needed
46
- return { template: {} };
47
- }
48
- return { template: '' };
49
- };
50
- exports.generateStackTemplate = generateStackTemplate;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deleteBucketResource = exports.updateBucketResource = exports.readBucketResource = exports.createBucketResource = void 0;
4
+ const types_1 = require("../../types");
4
5
  const tencentClient_1 = require("../../common/tencentClient");
5
6
  const cosTypes_1 = require("./cosTypes");
6
7
  const stateManager_1 = require("../../common/stateManager");
@@ -68,21 +69,40 @@ const createBucketResource = async (context, bucket, state) => {
68
69
  const config = (0, cosTypes_1.bucketToCosBucketConfig)(bucket, context.region);
69
70
  const client = (0, tencentClient_1.createTencentClient)(context);
70
71
  await client.cos.createBucket(config);
71
- // Refresh state from provider to get all attributes
72
72
  const bucketInfo = await client.cos.getBucket(bucket.name, context.region);
73
73
  if (!bucketInfo) {
74
74
  throw new Error(`Failed to refresh state for bucket: ${bucket.name}`);
75
75
  }
76
76
  const definition = (0, cosTypes_1.extractCosBucketDefinition)(config);
77
77
  const sid = (0, common_1.buildSid)('tencent', 'cos', context.stage, bucket.name);
78
+ const logicalId = `buckets.${bucket.key}`;
79
+ const instances = [
80
+ buildCosInstanceFromProvider(bucketInfo, sid),
81
+ ];
82
+ let cnameInfo;
83
+ if (bucket.website?.domain) {
84
+ logger_1.logger.info(`Binding custom domain ${bucket.website.domain} to bucket ${bucket.name}`);
85
+ cnameInfo = await client.cos.bindCustomDomain(bucket.name, bucket.website.domain);
86
+ if (cnameInfo) {
87
+ const instanceId = cnameInfo.dnsRecordId ?? bucket.website.domain;
88
+ const dnsInstance = {
89
+ sid: (0, common_1.buildSid)('tencent', 'dnspod', context.stage, instanceId),
90
+ id: instanceId,
91
+ type: types_1.ResourceTypeEnum.COS_DNS_CNAME,
92
+ domain: bucket.website.domain,
93
+ cname: cnameInfo.cname,
94
+ ...(cnameInfo.dnsRecordId ? { dnsRecordId: cnameInfo.dnsRecordId } : {}),
95
+ };
96
+ instances.push(dnsInstance);
97
+ }
98
+ }
78
99
  const resourceState = {
79
100
  mode: 'managed',
80
101
  region: context.region,
81
102
  definition,
82
- instances: [buildCosInstanceFromProvider(bucketInfo, sid)],
103
+ instances,
83
104
  lastUpdated: new Date().toISOString(),
84
105
  };
85
- const logicalId = `buckets.${bucket.key}`;
86
106
  return (0, stateManager_1.setResource)(state, logicalId, resourceState);
87
107
  };
88
108
  exports.createBucketResource = createBucketResource;
@@ -94,34 +114,64 @@ exports.readBucketResource = readBucketResource;
94
114
  const updateBucketResource = async (context, bucket, state) => {
95
115
  const config = (0, cosTypes_1.bucketToCosBucketConfig)(bucket, context.region);
96
116
  const client = (0, tencentClient_1.createTencentClient)(context);
97
- // Update ACL if specified
98
117
  if (config.ACL) {
99
118
  await client.cos.updateBucketAcl(bucket.name, context.region, config.ACL);
100
119
  }
101
- // Update website configuration if specified
102
120
  if (config.WebsiteConfiguration) {
103
121
  await client.cos.updateBucketWebsite(bucket.name, context.region, config.WebsiteConfiguration);
104
122
  }
105
- // Refresh state from provider to get all attributes
106
123
  const bucketInfo = await client.cos.getBucket(bucket.name, context.region);
107
124
  if (!bucketInfo) {
108
125
  throw new Error(`Failed to refresh state for bucket: ${bucket.name}`);
109
126
  }
110
127
  const definition = (0, cosTypes_1.extractCosBucketDefinition)(config);
111
128
  const sid = (0, common_1.buildSid)('tencent', 'cos', context.stage, bucket.name);
129
+ const logicalId = `buckets.${bucket.key}`;
130
+ const instances = [
131
+ buildCosInstanceFromProvider(bucketInfo, sid),
132
+ ];
133
+ const existingState = state.resources[logicalId];
134
+ const existingDnsInstance = existingState?.instances?.find((i) => i.type === types_1.ResourceTypeEnum.COS_DNS_CNAME);
135
+ if (bucket.website?.domain) {
136
+ const domainChanged = existingDnsInstance?.domain !== bucket.website.domain;
137
+ if (domainChanged && existingDnsInstance) {
138
+ await client.cos.unbindCustomDomain(bucket.name, existingDnsInstance.domain, existingDnsInstance.dnsRecordId);
139
+ }
140
+ logger_1.logger.info(`Binding custom domain ${bucket.website.domain} to bucket ${bucket.name}`);
141
+ const cnameInfo = await client.cos.bindCustomDomain(bucket.name, bucket.website.domain);
142
+ if (cnameInfo) {
143
+ const instanceId = cnameInfo.dnsRecordId ?? bucket.website.domain;
144
+ const dnsInstance = {
145
+ sid: (0, common_1.buildSid)('tencent', 'dnspod', context.stage, instanceId),
146
+ id: instanceId,
147
+ type: types_1.ResourceTypeEnum.COS_DNS_CNAME,
148
+ domain: bucket.website.domain,
149
+ cname: cnameInfo.cname,
150
+ ...(cnameInfo.dnsRecordId ? { dnsRecordId: cnameInfo.dnsRecordId } : {}),
151
+ };
152
+ instances.push(dnsInstance);
153
+ }
154
+ }
155
+ else if (existingDnsInstance) {
156
+ await client.cos.unbindCustomDomain(bucket.name, existingDnsInstance.domain, existingDnsInstance.dnsRecordId);
157
+ }
112
158
  const resourceState = {
113
159
  mode: 'managed',
114
160
  region: context.region,
115
161
  definition,
116
- instances: [buildCosInstanceFromProvider(bucketInfo, sid)],
162
+ instances,
117
163
  lastUpdated: new Date().toISOString(),
118
164
  };
119
- const logicalId = `buckets.${bucket.key}`;
120
165
  return (0, stateManager_1.setResource)(state, logicalId, resourceState);
121
166
  };
122
167
  exports.updateBucketResource = updateBucketResource;
123
168
  const deleteBucketResource = async (context, bucketName, region, logicalId, state) => {
124
169
  const client = (0, tencentClient_1.createTencentClient)(context);
170
+ const existingState = state.resources[logicalId];
171
+ const dnsInstance = existingState?.instances?.find((i) => i.type === types_1.ResourceTypeEnum.COS_DNS_CNAME);
172
+ if (dnsInstance) {
173
+ await client.cos.unbindCustomDomain(bucketName, dnsInstance.domain, dnsInstance.dnsRecordId);
174
+ }
125
175
  try {
126
176
  await client.cos.deleteBucket(bucketName, region);
127
177
  }
@@ -3,18 +3,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PartialResourceError = exports.CURRENT_STATE_VERSION = exports.ResourceTypeEnum = void 0;
4
4
  var ResourceTypeEnum;
5
5
  (function (ResourceTypeEnum) {
6
+ // Tencent Cloud
6
7
  ResourceTypeEnum["SCF_FUNCTION"] = "SCF_FUNCTION";
7
8
  ResourceTypeEnum["COS_BUCKET"] = "COS_BUCKET";
9
+ ResourceTypeEnum["COS_DNS_CNAME"] = "TENCENT_COS_DNS_CNAME";
8
10
  ResourceTypeEnum["TDSQL_C_SERVERLESS"] = "TDSQL_C_SERVERLESS";
11
+ // Aliyun - Primary Resources
9
12
  ResourceTypeEnum["ALIYUN_FC3_FUNCTION"] = "ALIYUN_FC3_FUNCTION";
10
13
  ResourceTypeEnum["ALIYUN_APIGW_GROUP"] = "ALIYUN_APIGW_GROUP";
11
14
  ResourceTypeEnum["ALIYUN_APIGW_API"] = "ALIYUN_APIGW_API";
12
15
  ResourceTypeEnum["ALIYUN_APIGW_DEPLOYMENT"] = "ALIYUN_APIGW_DEPLOYMENT";
13
16
  ResourceTypeEnum["ALIYUN_APIGW_DNS_VERIFICATION"] = "ALIYUN_APIGW_DNS_VERIFICATION";
14
17
  ResourceTypeEnum["ALIYUN_OSS_BUCKET"] = "ALIYUN_OSS_BUCKET";
18
+ ResourceTypeEnum["ALIYUN_OSS_DNS_CNAME"] = "ALIYUN_OSS_DNS_CNAME";
15
19
  ResourceTypeEnum["ALIYUN_RDS_SERVERLESS"] = "ALIYUN_RDS_SERVERLESS";
16
20
  ResourceTypeEnum["ALIYUN_ES_SERVERLESS"] = "ALIYUN_ES_SERVERLESS";
17
21
  ResourceTypeEnum["ALIYUN_TABLESTORE_TABLE"] = "ALIYUN_TABLESTORE_TABLE";
22
+ // Aliyun - FC3 Dependent Resources
23
+ ResourceTypeEnum["ALIYUN_SLS_PROJECT"] = "ALIYUN_SLS_PROJECT";
24
+ ResourceTypeEnum["ALIYUN_SLS_LOGSTORE"] = "ALIYUN_SLS_LOGSTORE";
25
+ ResourceTypeEnum["ALIYUN_SLS_INDEX"] = "ALIYUN_SLS_INDEX";
26
+ ResourceTypeEnum["ALIYUN_RAM_ROLE"] = "ALIYUN_RAM_ROLE";
27
+ ResourceTypeEnum["ALIYUN_ECS_SECURITY_GROUP"] = "ALIYUN_ECS_SECURITY_GROUP";
28
+ ResourceTypeEnum["ALIYUN_NAS_ACCESS_GROUP"] = "ALIYUN_NAS_ACCESS_GROUP";
29
+ ResourceTypeEnum["ALIYUN_NAS_FILE_SYSTEM"] = "ALIYUN_NAS_FILE_SYSTEM";
30
+ ResourceTypeEnum["ALIYUN_NAS_MOUNT_TARGET"] = "ALIYUN_NAS_MOUNT_TARGET";
18
31
  })(ResourceTypeEnum || (exports.ResourceTypeEnum = ResourceTypeEnum = {}));
19
32
  exports.CURRENT_STATE_VERSION = '3.0';
20
33
  class PartialResourceError extends Error {
@@ -33,7 +33,7 @@ exports.bucketSchema = {
33
33
  security: {
34
34
  type: 'object',
35
35
  properties: {
36
- access: (0, templateRefSchema_1.resolvableEnum)(['PRIVATE', 'PUBLIC_READ', 'PUBLIC_READ_WRITE']),
36
+ acl: (0, templateRefSchema_1.resolvableEnum)(['PRIVATE', 'PUBLIC_READ', 'PUBLIC_READ_WRITE']),
37
37
  force_delete: templateRefSchema_1.resolvableBoolean,
38
38
  sse_algorithm: {
39
39
  type: 'string',
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolvableEnum = exports.resolvableBoolean = exports.resolvableInteger = exports.resolvableNumber = void 0;
4
4
  // Template reference pattern that matches ${vars.xxx}, ${stages.xxx}, ${ctx.xxx}, ${functions.xxx}
5
- // Note: ${functions.xxx} references are kept as strings and resolved by infrastructure stack (ROS/Terraform)
5
+ // Note: ${functions.xxx} references are kept as strings and resolved by the deployment engine
6
6
  // Only ${vars.xxx}, ${stages.xxx}, and ${ctx.xxx} are resolved at parse time
7
7
  const templateRefPattern = '^\\$\\{(vars|stages|ctx|functions)\\.[\\w.]+\\}$';
8
8
  // Schema definition for a template reference string