@geek-fun/serverlessinsight 0.7.0 → 0.7.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 (42) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +58 -1
  3. package/README.zh-CN.md +3 -1
  4. package/dist/package.json +37 -35
  5. package/dist/src/commands/index.js +1 -3
  6. package/dist/src/commands/local.js +1 -2
  7. package/dist/src/common/aliyunClient/apigwOperations.js +9 -4
  8. package/dist/src/common/aliyunClient/cdnOperations.js +191 -0
  9. package/dist/src/common/aliyunClient/ecsOperations.js +2 -2
  10. package/dist/src/common/aliyunClient/fc3Operations.js +1 -1
  11. package/dist/src/common/aliyunClient/index.js +8 -0
  12. package/dist/src/common/aliyunClient/ossOperations.js +62 -2
  13. package/dist/src/common/aliyunClient/ramOperations.js +1 -1
  14. package/dist/src/common/hashUtils.js +4 -0
  15. package/dist/src/common/iacHelper.js +5 -0
  16. package/dist/src/common/lockManager.js +8 -0
  17. package/dist/src/common/planFormatter.js +4 -0
  18. package/dist/src/common/retryUtils.js +1 -1
  19. package/dist/src/common/stateManager.js +10 -0
  20. package/dist/src/common/volcengineClient/apigwOperations.js +1 -1
  21. package/dist/src/lang/en.js +16 -1
  22. package/dist/src/lang/zh-CN.js +17 -2
  23. package/dist/src/parser/bucketParser.js +111 -46
  24. package/dist/src/stack/aliyunStack/apigwResource.js +310 -47
  25. package/dist/src/stack/aliyunStack/apigwTypes.js +61 -1
  26. package/dist/src/stack/aliyunStack/ossResource.js +401 -69
  27. package/dist/src/stack/aliyunStack/ossTypes.js +58 -16
  28. package/dist/src/stack/localStack/event.js +1 -1
  29. package/dist/src/stack/localStack/functionRunner.js +4 -1
  30. package/dist/src/stack/scfStack/cosTypes.js +3 -6
  31. package/dist/src/stack/volcengineStack/tosTypes.js +1 -3
  32. package/dist/src/types/domains/state.js +3 -0
  33. package/dist/src/validator/bucketSchema.js +124 -56
  34. package/dist/src/validator/eventSchema.js +20 -0
  35. package/dist/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +37 -35
  37. package/samples/README_TENCENT_COS.md +3 -15
  38. package/samples/aliyun-poc-bucket-cdn.yml +63 -0
  39. package/samples/aliyun-poc-bucket.yml +0 -2
  40. package/samples/aliyun-poc-domain.yml +0 -2
  41. package/samples/tencent-poc-cos.yml +0 -2
  42. package/samples/volcengine-poc-bucket.yml +0 -1
@@ -36,7 +36,7 @@ const parseXmlResponse = (xml, tagName) => {
36
36
  return null;
37
37
  }
38
38
  };
39
- const createOssOperations = (ossClient, region, dnsOps) => {
39
+ /* istanbul ignore next */ const createOssOperations = (ossClient, region, dnsOps) => {
40
40
  const useBucket = (bucketName) => {
41
41
  ossClient.useBucket(bucketName);
42
42
  };
@@ -232,7 +232,7 @@ const createOssOperations = (ossClient, region, dnsOps) => {
232
232
  logger_1.logger.warn(lang_1.lang.__('OSS_CORS_RULE_REMOVE_FAILED', { domain, error: String(error) }));
233
233
  }
234
234
  };
235
- const bindCustomDomain = async (bucketName, domain, certificate) => {
235
+ const bindCustomDomain = async (bucketName, domain, certificate, skipDns) => {
236
236
  const normalizedDomain = (0, domainUtils_1.normalizeDomain)(domain);
237
237
  const mainDomain = (0, domainUtils_1.extractMainDomain)(normalizedDomain);
238
238
  const hostRecord = (0, domainUtils_1.extractHostRecord)(normalizedDomain, mainDomain);
@@ -249,6 +249,10 @@ const createOssOperations = (ossClient, region, dnsOps) => {
249
249
  logger_1.logger.info(lang_1.lang.__('OSS_BUCKET_CERT_BOUND', { domain: normalizedDomain }));
250
250
  }
251
251
  await addCorsRuleForDomain(bucketName, normalizedDomain);
252
+ // When skipDns is true, caller manages DNS separately (e.g. CDN mode)
253
+ if (skipDns) {
254
+ return { domain: normalizedDomain, cname: ossEndpoint, bucketCnameBound, txtRecordId };
255
+ }
252
256
  if (!dnsOps) {
253
257
  logger_1.logger.warn(lang_1.lang.__('OSS_DNS_MANUAL_CONFIG_REQUIRED', { domain: normalizedDomain, cname: ossEndpoint }));
254
258
  return { domain: normalizedDomain, cname: ossEndpoint, bucketCnameBound, txtRecordId };
@@ -501,6 +505,8 @@ const createOssOperations = (ossClient, region, dnsOps) => {
501
505
  await ossClient.putBucketWebsite(config.bucketName, {
502
506
  index: config.websiteConfig.indexDocument,
503
507
  error: config.websiteConfig.errorDocument,
508
+ supportSubDir: true,
509
+ type: 2,
504
510
  });
505
511
  }
506
512
  return {
@@ -653,6 +659,8 @@ const createOssOperations = (ossClient, region, dnsOps) => {
653
659
  await ossClient.putBucketWebsite(bucketName, {
654
660
  index: websiteConfig.indexDocument,
655
661
  error: websiteConfig.errorDocument,
662
+ supportSubDir: true,
663
+ type: 2,
656
664
  });
657
665
  },
658
666
  deleteBucketWebsite: async (bucketName) => {
@@ -709,9 +717,61 @@ const createOssOperations = (ossClient, region, dnsOps) => {
709
717
  useBucket(bucketName);
710
718
  await ossClient.put(objectKey, filePath);
711
719
  },
720
+ enableTransferAcceleration: async (bucketName) => {
721
+ useBucket(bucketName);
722
+ try {
723
+ const xml = `<?xml version="1.0" encoding="UTF-8"?>
724
+ <TransferAccelerationConfiguration>
725
+ <Enabled>true</Enabled>
726
+ </TransferAccelerationConfiguration>`;
727
+ const params = {
728
+ method: 'PUT',
729
+ bucket: bucketName,
730
+ subres: { transferAcceleration: '' },
731
+ headers: { 'Content-Type': 'application/xml' },
732
+ content: xml,
733
+ successStatuses: [200],
734
+ };
735
+ await ossRequest(ossClient, params);
736
+ logger_1.logger.info(lang_1.lang.__('OSS_TRANSFER_ACCELERATION_ENABLED', { bucketName }));
737
+ return true;
738
+ }
739
+ catch (error) {
740
+ logger_1.logger.warn(lang_1.lang.__('OSS_TRANSFER_ACCELERATION_ENABLE_FAILED', {
741
+ bucketName,
742
+ error: String(error),
743
+ }));
744
+ return false;
745
+ }
746
+ },
747
+ getTransferAccelerationStatus: async (bucketName) => {
748
+ useBucket(bucketName);
749
+ try {
750
+ const params = {
751
+ method: 'GET',
752
+ bucket: bucketName,
753
+ subres: { transferAcceleration: '' },
754
+ successStatuses: [200],
755
+ };
756
+ const response = await ossRequest(ossClient, params);
757
+ const xml = response.data || '';
758
+ const match = /<Enabled>(\w+)<\/Enabled>/.exec(xml);
759
+ return match?.[1]?.toLowerCase() === 'true';
760
+ }
761
+ catch {
762
+ return false;
763
+ }
764
+ },
765
+ getAccelerateEndpoint: async (bucketName) => {
766
+ const infoResult = await ossClient.getBucketInfo(bucketName);
767
+ const bucket = infoResult.bucket;
768
+ const actualBucketName = bucket.Name || bucketName;
769
+ return `${actualBucketName}.oss-accelerate.aliyuncs.com`;
770
+ },
712
771
  bindCustomDomain,
713
772
  unbindCustomDomain,
714
773
  createCnameToken,
774
+ getBucketCnameEndpoint,
715
775
  };
716
776
  };
717
777
  exports.createOssOperations = createOssOperations;
@@ -92,7 +92,7 @@ const FC_EXECUTION_POLICY = JSON.stringify({
92
92
  },
93
93
  ],
94
94
  });
95
- const createRamOperations = (ramClient) => {
95
+ /* istanbul ignore next */ const createRamOperations = (ramClient) => {
96
96
  const attachRolePolicyForFc = async (roleName) => {
97
97
  const policyName = `${roleName}-policy`;
98
98
  // Create policy
@@ -7,11 +7,13 @@ exports.diffAttributes = exports.attributesEqual = exports.computeDirectoryHash
7
7
  const node_crypto_1 = __importDefault(require("node:crypto"));
8
8
  const node_fs_1 = __importDefault(require("node:fs"));
9
9
  const node_path_1 = __importDefault(require("node:path"));
10
+ /* istanbul ignore next */
10
11
  const computeFileHash = (filePath) => {
11
12
  const fileBuffer = node_fs_1.default.readFileSync(filePath);
12
13
  return node_crypto_1.default.createHash('sha256').update(fileBuffer).digest('hex');
13
14
  };
14
15
  exports.computeFileHash = computeFileHash;
16
+ /* istanbul ignore next */
15
17
  const computeDirectoryHash = (dirPath) => {
16
18
  const files = [];
17
19
  const collectFiles = (currentPath) => {
@@ -105,6 +107,7 @@ const deepEqual = (a, b) => {
105
107
  * @param b - Second attributes object
106
108
  * @returns True if objects are equal, false otherwise
107
109
  */
110
+ /* istanbul ignore next */
108
111
  const attributesEqual = (a, b) => {
109
112
  return deepEqual(a, b);
110
113
  };
@@ -116,6 +119,7 @@ exports.attributesEqual = attributesEqual;
116
119
  * @param after - New attributes
117
120
  * @returns Object with changed, added, and removed keys
118
121
  */
122
+ /* istanbul ignore next */
119
123
  const diffAttributes = (before, after) => {
120
124
  const changed = {};
121
125
  const added = {};
@@ -10,12 +10,14 @@ const lodash_1 = require("lodash");
10
10
  const parser_1 = require("../parser");
11
11
  const logger_1 = require("./logger");
12
12
  const lang_1 = require("../lang");
13
+ /* istanbul ignore next */
13
14
  const resolveCode = (location) => {
14
15
  const filePath = node_path_1.default.resolve(process.cwd(), location);
15
16
  const fileContent = node_fs_1.default.readFileSync(filePath);
16
17
  return fileContent.toString('base64');
17
18
  };
18
19
  exports.resolveCode = resolveCode;
20
+ /* istanbul ignore next */
19
21
  const readCodeSize = (location) => {
20
22
  const filePath = node_path_1.default.resolve(process.cwd(), location);
21
23
  const stats = node_fs_1.default.statSync(filePath);
@@ -43,6 +45,7 @@ const inferType = (value, wasTemplateRef) => {
43
45
  }
44
46
  return value;
45
47
  };
48
+ /* istanbul ignore next */
46
49
  const calcValue = (rawValue, ctx, iacVars) => {
47
50
  const containsStage = rawValue.match(/\$\{ctx.stage}/);
48
51
  const containsVar = rawValue.match(/\$\{vars.\w+}/);
@@ -83,6 +86,7 @@ const calcValue = (rawValue, ctx, iacVars) => {
83
86
  return inferType(value, isExactTemplateRef);
84
87
  };
85
88
  exports.calcValue = calcValue;
89
+ /* istanbul ignore next */
86
90
  const getIacDefinition = (iac, rawValue) => {
87
91
  const matchFn = rawValue.match(/^\$\{functions\.(\w+(\.\w+)?)}$/);
88
92
  if (matchFn?.length) {
@@ -91,6 +95,7 @@ const getIacDefinition = (iac, rawValue) => {
91
95
  return iac.functions?.find((fc) => fc.key === rawValue);
92
96
  };
93
97
  exports.getIacDefinition = getIacDefinition;
98
+ /* istanbul ignore next */
94
99
  const isFunctionDomain = (def) => {
95
100
  return def != null && typeof def.key === 'string';
96
101
  };
@@ -20,10 +20,12 @@ class LockError extends Error {
20
20
  }
21
21
  }
22
22
  exports.LockError = LockError;
23
+ /* istanbul ignore next */
23
24
  const getLockPath = (statePath) => {
24
25
  return `${statePath}${constants_1.LOCK_FILE_SUFFIX}`;
25
26
  };
26
27
  exports.getLockPath = getLockPath;
28
+ /* istanbul ignore next */
27
29
  const generateLockId = () => {
28
30
  return node_crypto_1.default.randomBytes(16).toString('hex');
29
31
  };
@@ -117,6 +119,7 @@ const getTimeAgo = (acquiredAt) => {
117
119
  }
118
120
  }
119
121
  };
122
+ /* istanbul ignore next */
120
123
  const formatLockInfo = (lock) => {
121
124
  const acquiredAt = new Date(lock.acquiredAt);
122
125
  const timeAgo = getTimeAgo(acquiredAt);
@@ -134,6 +137,7 @@ exports.formatLockInfo = formatLockInfo;
134
137
  const sleep = (ms) => {
135
138
  return new Promise((resolve) => setTimeout(resolve, ms));
136
139
  };
140
+ /* istanbul ignore next */
137
141
  const acquireLockInternal = async (statePath, operation, options = {}) => {
138
142
  const timeout = options.timeout ?? constants_1.DEFAULT_LOCK_TIMEOUT;
139
143
  const retryDelay = options.retryDelay ?? constants_1.DEFAULT_LOCK_RETRY_DELAY;
@@ -199,6 +203,7 @@ const acquireLockInternal = async (statePath, operation, options = {}) => {
199
203
  throw new LockError(`Failed to acquire lock.\n${existingLock ? (0, exports.formatLockInfo)(existingLock) : ''}\nIf you are certain no other operation is running, use:\n si force-unlock ${existingLock?.id || 'unknown'}`, existingLock || undefined);
200
204
  };
201
205
  exports.acquireLockInternal = acquireLockInternal;
206
+ /* istanbul ignore next */
202
207
  const releaseLockInternal = (statePath, lockId) => {
203
208
  const lockPath = (0, exports.getLockPath)(statePath);
204
209
  const existingLock = readLockFile(lockPath);
@@ -208,6 +213,7 @@ const releaseLockInternal = (statePath, lockId) => {
208
213
  }
209
214
  };
210
215
  exports.releaseLockInternal = releaseLockInternal;
216
+ /* istanbul ignore next */
211
217
  const forceUnlock = (statePath, lockId) => {
212
218
  const lockPath = (0, exports.getLockPath)(statePath);
213
219
  const existingLock = readLockFile(lockPath);
@@ -221,6 +227,7 @@ const forceUnlock = (statePath, lockId) => {
221
227
  return true;
222
228
  };
223
229
  exports.forceUnlock = forceUnlock;
230
+ /* istanbul ignore next */
224
231
  const withLock = async (statePath, operation, fn, options) => {
225
232
  let lock = null;
226
233
  try {
@@ -235,6 +242,7 @@ const withLock = async (statePath, operation, fn, options) => {
235
242
  };
236
243
  exports.withLock = withLock;
237
244
  // Export only for forceUnlock command which needs to read lock info
245
+ /* istanbul ignore next */
238
246
  const readLockFileForCommand = (statePath) => {
239
247
  const lockPath = (0, exports.getLockPath)(statePath);
240
248
  return readLockFile(lockPath);
@@ -38,6 +38,7 @@ const isSimpleObject = (val) => {
38
38
  const obj = val;
39
39
  return Object.values(obj).every((v) => typeof v !== 'object' || v === null);
40
40
  };
41
+ /* istanbul ignore next */
41
42
  const computeAttributeDiffs = (before, after) => {
42
43
  if (!before && !after)
43
44
  return { diffs: [], unchangedCount: 0 };
@@ -205,6 +206,7 @@ const ACTION_COLOR = {
205
206
  delete: 'RED',
206
207
  refresh: 'CYAN',
207
208
  };
209
+ /* istanbul ignore next */
208
210
  const formatPlanItem = (item, config = DEFAULT_CONFIG) => {
209
211
  const descKey = ACTION_DESC[item.action] ?? 'PLAN_NO_CHANGES';
210
212
  const headerLine = ` # ${item.logicalId} ${lang_1.lang.__(descKey)}`;
@@ -230,6 +232,7 @@ const formatPlanItem = (item, config = DEFAULT_CONFIG) => {
230
232
  return [headerLine, resourceLine, ...attrLines, ...hiddenLine].join('\n');
231
233
  };
232
234
  exports.formatPlanItem = formatPlanItem;
235
+ /* istanbul ignore next */
233
236
  const formatPlan = (items, config = DEFAULT_CONFIG) => {
234
237
  if (items.length === 0) {
235
238
  return lang_1.lang.__('NO_CHANGES_INFRASTRUCTURE_UP_TO_DATE');
@@ -262,6 +265,7 @@ const formatPlan = (items, config = DEFAULT_CONFIG) => {
262
265
  return [...header, ...itemLines, summary].join('\n');
263
266
  };
264
267
  exports.formatPlan = formatPlan;
268
+ /* istanbul ignore next */
265
269
  const displayPlan = (planResult) => {
266
270
  const output = (0, exports.formatPlan)(planResult.items);
267
271
  logger_1.logger.info(output);
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sleep = void 0;
4
- const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
4
+ /* istanbul ignore next */ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
5
5
  exports.sleep = sleep;
@@ -9,10 +9,12 @@ const node_path_1 = __importDefault(require("node:path"));
9
9
  const types_1 = require("../types");
10
10
  const lockManager_1 = require("./lockManager");
11
11
  const STATE_DIR = '.serverlessinsight';
12
+ /* istanbul ignore next */
12
13
  const getStatePath = (app, service, baseDir = process.cwd()) => {
13
14
  return node_path_1.default.join(baseDir, STATE_DIR, `state-${app}-${service}.json`);
14
15
  };
15
16
  exports.getStatePath = getStatePath;
17
+ /* istanbul ignore next */
16
18
  const ensureStateDir = (baseDir = process.cwd()) => {
17
19
  const stateDir = node_path_1.default.join(baseDir, STATE_DIR);
18
20
  if (!node_fs_1.default.existsSync(stateDir)) {
@@ -24,6 +26,7 @@ exports.ensureStateDir = ensureStateDir;
24
26
  * Load state file, scoped to the given stage.
25
27
  * The returned StateFile has `resources` populated from `stages[stage].resources`.
26
28
  */
29
+ /* istanbul ignore next */
27
30
  const loadState = (provider, app, service, stage, baseDir = process.cwd()) => {
28
31
  const statePath = (0, exports.getStatePath)(app, service, baseDir);
29
32
  try {
@@ -41,6 +44,7 @@ const loadState = (provider, app, service, stage, baseDir = process.cwd()) => {
41
44
  return { version: types_1.CURRENT_STATE_VERSION, provider, app, service, stages: {}, resources: {} };
42
45
  };
43
46
  exports.loadState = loadState;
47
+ /* istanbul ignore next */
44
48
  const saveState = (state, app, service, stage, baseDir = process.cwd()) => {
45
49
  (0, exports.ensureStateDir)(baseDir);
46
50
  const statePath = (0, exports.getStatePath)(app, service, baseDir);
@@ -82,6 +86,7 @@ exports.saveState = saveState;
82
86
  * Save state with automatic locking.
83
87
  * This should be used by high-level operations like deploy/destroy.
84
88
  */
89
+ /* istanbul ignore next */
85
90
  const saveStateWithLock = async (state, app, service, stage, operation, baseDir = process.cwd(), options) => {
86
91
  const statePath = (0, exports.getStatePath)(app, service, baseDir);
87
92
  await (0, lockManager_1.withLock)(statePath, operation, async () => {
@@ -89,10 +94,12 @@ const saveStateWithLock = async (state, app, service, stage, operation, baseDir
89
94
  }, options);
90
95
  };
91
96
  exports.saveStateWithLock = saveStateWithLock;
97
+ /* istanbul ignore next */
92
98
  const getResource = (state, resourceId) => {
93
99
  return state.resources[resourceId];
94
100
  };
95
101
  exports.getResource = getResource;
102
+ /* istanbul ignore next */
96
103
  const setResource = (state, resourceId, resourceState) => {
97
104
  return {
98
105
  ...state,
@@ -103,6 +110,7 @@ const setResource = (state, resourceId, resourceState) => {
103
110
  };
104
111
  };
105
112
  exports.setResource = setResource;
113
+ /* istanbul ignore next */
106
114
  const removeResource = (state, resourceId) => {
107
115
  const { [resourceId]: _, ...remainingResources } = state.resources;
108
116
  return {
@@ -111,6 +119,7 @@ const removeResource = (state, resourceId) => {
111
119
  };
112
120
  };
113
121
  exports.removeResource = removeResource;
122
+ /* istanbul ignore next */
114
123
  const getAllResources = (state) => {
115
124
  return state.resources;
116
125
  };
@@ -119,6 +128,7 @@ exports.getAllResources = getAllResources;
119
128
  * Extract role ARN from function state for event resources.
120
129
  * Looks through all function resources to find a RAM role instance and returns its ARN.
121
130
  */
131
+ /* istanbul ignore next */
122
132
  const getRoleArnFromState = (state) => {
123
133
  const allResources = (0, exports.getAllResources)(state);
124
134
  for (const [logicalId, resourceState] of Object.entries(allResources)) {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createApigwOperations = void 0;
4
4
  const logger_1 = require("../logger");
5
5
  const lang_1 = require("../../lang");
6
- const createApigwOperations = (client) => {
6
+ /* istanbul ignore next */ const createApigwOperations = (client) => {
7
7
  if (!client) {
8
8
  return {
9
9
  createGateway: async (_config) => {
@@ -48,7 +48,7 @@ exports.en = {
48
48
  LOCAL_SERVER_STOPPED: 'localServer stopped',
49
49
  LOCAL_GATEWAY_ERROR: 'Local gateway error',
50
50
  ERROR_STOPPING_LOCAL_SERVER: 'Error stopping localServer',
51
- RUN_LOCAL_STARTING: 'run-local starting: stage={{stage}} port={{port}} debug={{debug}} watch={{watch}}',
51
+ RUN_LOCAL_STARTING: 'run-local starting: stage={{stage}} debug={{debug}} watch={{watch}}',
52
52
  // Function execution
53
53
  FUNCTION_REQUEST_RECEIVED: 'Function request received by local server -> {{method}} {{identifier}} ',
54
54
  INVOKING_WORKER_WITH_EVENT_TYPE: 'Invoking worker with event type: {{eventType}} and context',
@@ -642,4 +642,19 @@ exports.en = {
642
642
  VEFAAS_DEPENDENT_RESOURCES_TRACKED: 'Dependent resources (TLS, IAM) are tracked in state',
643
643
  VEFAAS_CAN_RETRY_DEPLOYMENT: 'You can retry deployment - the system will reuse existing dependent resources',
644
644
  VEFAAS_FUNCTION_EXISTS_RECOVERY: 'Function {{functionName}} already exists in provider (tainted recovery), skipping create and refreshing state',
645
+ // CDN messages
646
+ ENABLING_OSS_TRANSFER_ACCELERATION: 'Enabling OSS transfer acceleration for bucket {{bucketName}}',
647
+ OSS_TRANSFER_ACCELERATION_ENABLED: 'OSS transfer acceleration enabled for bucket {{bucketName}}',
648
+ OSS_TRANSFER_ACCELERATION_ENABLE_FAILED: 'Failed to enable OSS transfer acceleration for bucket {{bucketName}}: {{error}}',
649
+ CREATING_CDN_DISTRIBUTION: 'Creating CDN distribution for {{domain}} with origin {{origin}}',
650
+ CDN_DEPLOYING_CERTIFICATE: 'Deploying SSL certificate to CDN domain {{domain}}',
651
+ CDN_DOMAIN_DELETED: 'CDN domain {{domain}} deleted successfully',
652
+ CDN_DOMAIN_DELETE_FAILED: 'Failed to delete CDN domain {{domain}}: {{error}}',
653
+ CDN_ACCELERATE_SKIP_UPDATE: 'CDN/accelerate configuration unchanged for {{domain}} on bucket {{bucketName}}. CDN settings are managed at create-time.',
654
+ CDN_DOMAIN_CHANGE_REQUIRES_RECREATE: 'Cannot change CDN/accelerate domain from {{oldDomain}} to {{newDomain}} during update. Use destroy+recreate instead.',
655
+ BUCKET_DOMAIN_DEPRECATED: '[DEPRECATED] bucket "{{key}}": website.domain is deprecated. Use top-level "domain" instead.',
656
+ FAILED_TO_REFRESH_STATE: 'Failed to refresh state for {{resourceType}}: {{name}}',
657
+ FAILED_TO_UPLOAD_BUCKET_FILES: 'Failed to upload files to bucket, but bucket was created and saved to state: {{error}}',
658
+ FAILED_TO_ENABLE_ACCELERATION: 'Failed to enable transfer acceleration for bucket {{bucketName}}',
659
+ CDN_ACCELERATE_CONFIG_CHANGED: 'Cannot change CDN/accelerate settings for bucket {{bucketName}} via update. Use destroy+recreate to change CDN or acceleration configuration.',
645
660
  };
@@ -48,7 +48,7 @@ exports.zhCN = {
48
48
  LOCAL_SERVER_STOPPED: '本地服务器已停止',
49
49
  LOCAL_GATEWAY_ERROR: '本地网关错误',
50
50
  ERROR_STOPPING_LOCAL_SERVER: '停止本地服务器时出错',
51
- RUN_LOCAL_STARTING: '启动本地运行: stage={{stage}} port={{port}} debug={{debug}} watch={{watch}}',
51
+ RUN_LOCAL_STARTING: '启动本地运行: stage={{stage}} debug={{debug}} watch={{watch}}',
52
52
  // Function execution
53
53
  FUNCTION_REQUEST_RECEIVED: '本地服务器收到函数请求 -> {{method}} {{identifier}} ',
54
54
  INVOKING_WORKER_WITH_EVENT_TYPE: '使用事件类型调用工作进程: {{eventType}} 和上下文',
@@ -635,5 +635,20 @@ exports.zhCN = {
635
635
  // Volcengine veFaaS dependent resources
636
636
  VEFAAS_DEPENDENT_RESOURCES_TRACKED: '依赖资源(TLS、IAM)已在状态中跟踪',
637
637
  VEFAAS_CAN_RETRY_DEPLOYMENT: '您可以重试部署 - 系统将复用现有的依赖资源',
638
- VEFAAS_FUNCTION_EXISTS_RECOVERY: '函数 {{functionName}} 在提供商中已存在(状态恢复中),跳过创建并刷新状态',
638
+ VEFAAS_FUNCTION_EXISTS_RECOVERY: '函数 {{functionName}} 已存在于云服务商(tainted 恢复),跳过创建并刷新状态',
639
+ // CDN messages
640
+ ENABLING_OSS_TRANSFER_ACCELERATION: '正在为存储桶 {{bucketName}} 开启 OSS 传输加速',
641
+ OSS_TRANSFER_ACCELERATION_ENABLED: '存储桶 {{bucketName}} 的 OSS 传输加速已开启',
642
+ OSS_TRANSFER_ACCELERATION_ENABLE_FAILED: '开启存储桶 {{bucketName}} 的传输加速失败:{{error}}',
643
+ CREATING_CDN_DISTRIBUTION: '正在为 {{domain}} 创建 CDN 加速域名,源站为 {{origin}}',
644
+ CDN_DEPLOYING_CERTIFICATE: '正在为 CDN 域名 {{domain}} 部署 SSL 证书',
645
+ CDN_DOMAIN_DELETED: 'CDN 域名 {{domain}} 已删除',
646
+ CDN_DOMAIN_DELETE_FAILED: '删除 CDN 域名 {{domain}} 失败:{{error}}',
647
+ CDN_ACCELERATE_SKIP_UPDATE: '{{domain}} 的 CDN/加速配置在存储桶 {{bucketName}} 上未变化。CDN 设置在创建时管理。',
648
+ CDN_DOMAIN_CHANGE_REQUIRES_RECREATE: '无法在更新时更改 CDN/加速域名从 {{oldDomain}} 到 {{newDomain}}。请使用销毁重建操作。',
649
+ BUCKET_DOMAIN_DEPRECATED: '[已弃用] 存储桶 "{{key}}": website.domain 已弃用,请使用顶层 "domain" 配置。',
650
+ FAILED_TO_REFRESH_STATE: '刷新 {{resourceType}} {{name}} 的状态失败',
651
+ FAILED_TO_UPLOAD_BUCKET_FILES: '上传文件到存储桶失败,但存储桶已创建并保存到状态:{{error}}',
652
+ FAILED_TO_ENABLE_ACCELERATION: '无法为存储桶 {{bucketName}} 开启传输加速',
653
+ CDN_ACCELERATE_CONFIG_CHANGED: '无法通过更新操作更改存储桶 {{bucketName}} 的 CDN/加速配置。请使用销毁重建操作来更改 CDN 或加速配置。',
639
654
  };
@@ -3,7 +3,51 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseBucket = void 0;
4
4
  const types_1 = require("../types");
5
5
  const parseUtils_1 = require("./parseUtils");
6
+ const logger_1 = require("../common/logger");
7
+ const lang_1 = require("../lang");
6
8
  const isStructuredDomain = (domain) => typeof domain === 'object' && domain !== null && 'domain_name' in domain;
9
+ const parseCdnConfig = (cdn) => {
10
+ if (cdn == null)
11
+ return undefined;
12
+ if (typeof cdn === 'boolean')
13
+ return cdn;
14
+ const parsed = { enabled: (0, parseUtils_1.parseBooleanWithDefault)(cdn.enabled, true) };
15
+ if (cdn.cdn_type != null)
16
+ parsed.cdn_type = String(cdn.cdn_type);
17
+ if (cdn.scope != null)
18
+ parsed.scope = String(cdn.scope);
19
+ if (cdn.cache_ttl != null)
20
+ parsed.cache_ttl = Number(cdn.cache_ttl);
21
+ if (cdn.ignore_query_string != null)
22
+ parsed.ignore_query_string = String(cdn.ignore_query_string) === 'true';
23
+ if (cdn.origin_protocol != null)
24
+ parsed.origin_protocol = String(cdn.origin_protocol);
25
+ if (cdn.compression != null)
26
+ parsed.compression = String(cdn.compression) === 'true';
27
+ if (cdn.force_redirect_https != null)
28
+ parsed.force_redirect_https = String(cdn.force_redirect_https) === 'true';
29
+ return parsed;
30
+ };
31
+ const parseDomainConfig = (rawDomain, accelerateFromDomain) => {
32
+ if (!rawDomain)
33
+ return undefined;
34
+ return {
35
+ domain_name: String(rawDomain.domain_name),
36
+ www_bind_apex: (0, parseUtils_1.parseBooleanWithDefault)(rawDomain.www_bind_apex, false),
37
+ certificate_id: rawDomain.certificate_id != null ? String(rawDomain.certificate_id) : undefined,
38
+ certificate_body: rawDomain.certificate_body != null ? String(rawDomain.certificate_body) : undefined,
39
+ certificate_private_key: rawDomain.certificate_private_key != null
40
+ ? String(rawDomain.certificate_private_key)
41
+ : undefined,
42
+ protocol: rawDomain.protocol != null
43
+ ? Array.isArray(rawDomain.protocol)
44
+ ? rawDomain.protocol.map(String)
45
+ : String(rawDomain.protocol)
46
+ : undefined,
47
+ cdn: parseCdnConfig(rawDomain.cdn),
48
+ accelerate: accelerateFromDomain != null ? String(accelerateFromDomain) === 'true' : undefined,
49
+ };
50
+ };
7
51
  const parseWebsiteDomain = (domain) => {
8
52
  if (domain == null) {
9
53
  return {
@@ -25,59 +69,80 @@ const parseWebsiteDomain = (domain) => {
25
69
  domain_protocol: undefined,
26
70
  };
27
71
  }
72
+ const d = domain;
28
73
  return {
29
- domain: String(domain.domain_name),
30
- www_bind_apex: (0, parseUtils_1.parseBooleanWithDefault)(domain.www_bind_apex, false),
31
- domain_certificate_id: domain.certificate_id != null ? String(domain.certificate_id) : undefined,
32
- domain_certificate_body: domain.certificate_body != null ? String(domain.certificate_body) : undefined,
33
- domain_certificate_private_key: domain.certificate_private_key != null ? String(domain.certificate_private_key) : undefined,
34
- domain_protocol: domain.protocol != null
35
- ? Array.isArray(domain.protocol)
36
- ? domain.protocol.map(String)
37
- : String(domain.protocol)
74
+ domain: String(d.domain_name),
75
+ www_bind_apex: (0, parseUtils_1.parseBooleanWithDefault)(d.www_bind_apex, false),
76
+ domain_certificate_id: d.certificate_id != null ? String(d.certificate_id) : undefined,
77
+ domain_certificate_body: d.certificate_body != null ? String(d.certificate_body) : undefined,
78
+ domain_certificate_private_key: d.certificate_private_key != null ? String(d.certificate_private_key) : undefined,
79
+ domain_protocol: d.protocol != null
80
+ ? Array.isArray(d.protocol)
81
+ ? d.protocol.map(String)
82
+ : String(d.protocol)
38
83
  : undefined,
39
84
  };
40
85
  };
86
+ /* istanbul ignore next */
41
87
  const parseBucket = (buckets) => {
42
88
  if (!buckets) {
43
89
  return undefined;
44
90
  }
45
- return Object.entries(buckets).map(([key, bucket]) => ({
46
- key,
47
- name: String(bucket.name),
48
- storage: bucket.storage
49
- ? {
50
- class: String(bucket.storage.class),
51
- }
52
- : undefined,
53
- versioning: bucket.versioning
54
- ? {
55
- status: String(bucket.versioning.status),
56
- }
57
- : undefined,
58
- security: bucket.security
59
- ? {
60
- acl: bucket.security.acl
61
- ? String(bucket.security.acl)
62
- : types_1.BucketAccessEnum.PRIVATE,
63
- force_delete: (0, parseUtils_1.parseBooleanWithDefault)(bucket.security.force_delete, false),
64
- sse_algorithm: bucket.security.sse_algorithm
65
- ? String(bucket.security.sse_algorithm)
66
- : undefined,
67
- sse_kms_master_key_id: bucket.security.sse_kms_master_key_id
68
- ? String(bucket.security.sse_kms_master_key_id)
69
- : undefined,
70
- }
71
- : undefined,
72
- website: bucket.website
73
- ? {
74
- code: String(bucket.website.code),
75
- ...parseWebsiteDomain(bucket.website.domain),
76
- index: (0, parseUtils_1.parseStringWithDefault)(bucket.website.index, 'index.html'),
77
- error_page: (0, parseUtils_1.parseStringWithDefault)(bucket.website.error_page, '404.html'),
78
- error_code: (0, parseUtils_1.parseNumberWithDefault)(bucket.website.error_code, 404),
79
- }
80
- : undefined,
81
- }));
91
+ return Object.entries(buckets).map(([key, bucket]) => {
92
+ let domainParsed = undefined;
93
+ // Parse top-level domain (canonical form)
94
+ if (bucket.domain) {
95
+ const structuredDomain = isStructuredDomain(bucket.domain)
96
+ ? bucket.domain
97
+ : { domain_name: String(bucket.domain) };
98
+ domainParsed = parseDomainConfig(structuredDomain, bucket.domain.accelerate);
99
+ }
100
+ // Fallback: parse website.domain (deprecated)
101
+ if (!domainParsed && bucket.website?.domain) {
102
+ logger_1.logger.warn(lang_1.lang.__('BUCKET_DOMAIN_DEPRECATED', { key }));
103
+ const structuredDomain = isStructuredDomain(bucket.website.domain)
104
+ ? bucket.website.domain
105
+ : { domain_name: String(bucket.website.domain) };
106
+ domainParsed = parseDomainConfig(structuredDomain, undefined);
107
+ }
108
+ const websiteDomain = parseWebsiteDomain(bucket.website?.domain);
109
+ return {
110
+ key,
111
+ name: String(bucket.name),
112
+ storage: bucket.storage
113
+ ? {
114
+ class: String(bucket.storage.class),
115
+ }
116
+ : undefined,
117
+ versioning: bucket.versioning
118
+ ? {
119
+ status: String(bucket.versioning.status),
120
+ }
121
+ : undefined,
122
+ security: bucket.security
123
+ ? {
124
+ acl: bucket.security.acl
125
+ ? String(bucket.security.acl)
126
+ : types_1.BucketAccessEnum.PRIVATE,
127
+ force_delete: (0, parseUtils_1.parseBooleanWithDefault)(bucket.security.force_delete, false),
128
+ sse_algorithm: bucket.security.sse_algorithm
129
+ ? String(bucket.security.sse_algorithm)
130
+ : undefined,
131
+ sse_kms_master_key_id: bucket.security.sse_kms_master_key_id
132
+ ? String(bucket.security.sse_kms_master_key_id)
133
+ : undefined,
134
+ }
135
+ : undefined,
136
+ // Parsed top-level domain config
137
+ domain: domainParsed,
138
+ website: bucket.website
139
+ ? {
140
+ code: String(bucket.website.code),
141
+ ...websiteDomain,
142
+ index: (0, parseUtils_1.parseStringWithDefault)(bucket.website.index, 'index.html'),
143
+ }
144
+ : undefined,
145
+ };
146
+ });
82
147
  };
83
148
  exports.parseBucket = parseBucket;